-
Notifications
You must be signed in to change notification settings - Fork 298
Relax restrictions for constants in value traits #6314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8e4a2c2
aafee80
5c77593
30f060a
9026ac6
4749835
c62e0b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| // RUN: %testDafnyForEachResolver --expect-exit-code=2 "%s" | ||||||
| // RUN: %testDafnyForEachResolver --expect-exit-code=2 "%s" -- --general-traits=datatype | ||||||
|
|
||||||
|
|
||||||
| module AutoInitRegressions { | ||||||
|
|
@@ -42,6 +42,13 @@ module AutoInitRegressions { | |||||
| static const Static: Y // error: Y is not auto-init | ||||||
| const Instance: Y // error: Y is not auto-init | ||||||
| } | ||||||
|
|
||||||
| trait PossiblyDatatypeTrait { | ||||||
| static const StaticField: Y // error: Y is not nonempty | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is the error appearing both in the static const declaration and the datatype, or just in the datatype? If the latter, this comment can be removed. |
||||||
| const InstanceField: Y | ||||||
| } | ||||||
|
|
||||||
| datatype PossiblyDatatypeTraitImpl extends PossiblyDatatypeTrait = PossiblyDatatypeTraitImpl { } // error | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| } | ||||||
|
|
||||||
| module NonemptyRegressions { | ||||||
|
|
@@ -79,4 +86,11 @@ module NonemptyRegressions { | |||||
| ghost static const Static: Y // error: Y is not nonempty | ||||||
| ghost const Instance: Y // error: Y is not nonempty | ||||||
| } | ||||||
|
|
||||||
| trait PossiblyDatatypeTrait { | ||||||
| ghost static const StaticField: Y // error: Y is not nonempty | ||||||
| ghost const InstanceField: Y | ||||||
| } | ||||||
|
|
||||||
| datatype PossiblyDatatypeTraitImpl extends PossiblyDatatypeTrait = PossiblyDatatypeTraitImpl { } // error | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an error here because InstanceField is not initialized? |
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,15 +9,19 @@ git-issue-1148.dfy(36,17): Error: static non-ghost const field 'Static' of type | |||||
| git-issue-1148.dfy(37,10): Error: non-ghost const field 'Instance' of type 'Y' (which does not have a default compiled value) must give a defining value | ||||||
| git-issue-1148.dfy(42,17): Error: static non-ghost const field 'Static' of type 'Y' (which does not have a default compiled value) must give a defining value | ||||||
| git-issue-1148.dfy(43,10): Error: non-ghost const field 'Instance' of type 'Y' (which does not have a default compiled value) must give a defining value | ||||||
| git-issue-1148.dfy(56,14): Error: static ghost const field 'Global' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(52,23): Error: static ghost const field 'Static' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(53,16): Error: ghost const field 'Instance' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(59,23): Error: static ghost const field 'StaticField' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(58,8): Error: class 'Class' with fields without known initializers, like 'InstanceField' of type 'Y', must declare a constructor | ||||||
| git-issue-1148.dfy(64,23): Error: static ghost const field 'StaticField' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(68,8): Error: class 'TraitImpl' with fields without known initializers, like 'InstanceField' of type 'Y', must declare a constructor | ||||||
| git-issue-1148.dfy(73,23): Error: static ghost const field 'Static' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(74,16): Error: ghost const field 'Instance' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(79,23): Error: static ghost const field 'Static' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(80,16): Error: ghost const field 'Instance' of type 'Y' (which may be empty) must give a defining value | ||||||
| 22 resolution/type errors detected in git-issue-1148.dfy | ||||||
| git-issue-1148.dfy(47,17): Error: static non-ghost const field 'StaticField' of type 'Y' (which does not have a default compiled value) must give a defining value | ||||||
| git-issue-1148.dfy(51,11): Error: datatype 'PossiblyDatatypeTraitImpl' must not inherit a non-ghost const field 'InstanceField' of type 'Y' (which does not have a default compiled value) without a defining value | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about a reformulation that gives two possible resolution outcomes?
Suggested change
That way we have less "must not", "does not", and "without". |
||||||
| git-issue-1148.dfy(63,14): Error: static ghost const field 'Global' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(59,23): Error: static ghost const field 'Static' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(60,16): Error: ghost const field 'Instance' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(66,23): Error: static ghost const field 'StaticField' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(65,8): Error: class 'Class' with fields without known initializers, like 'InstanceField' of type 'Y', must declare a constructor | ||||||
| git-issue-1148.dfy(71,23): Error: static ghost const field 'StaticField' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(75,8): Error: class 'TraitImpl' with fields without known initializers, like 'InstanceField' of type 'Y', must declare a constructor | ||||||
| git-issue-1148.dfy(80,23): Error: static ghost const field 'Static' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(81,16): Error: ghost const field 'Instance' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(86,23): Error: static ghost const field 'Static' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(87,16): Error: ghost const field 'Instance' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(91,23): Error: static ghost const field 'StaticField' of type 'Y' (which may be empty) must give a defining value | ||||||
| git-issue-1148.dfy(95,11): Error: datatype 'PossiblyDatatypeTraitImpl' must not inherit a ghost const field 'InstanceField' of type 'Y' (which may be empty) without a defining value | ||||||
| 26 resolution/type errors detected in git-issue-1148.dfy | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,14 +216,14 @@ module UninitializedConsts { | |
| ghost const A: AutoInit | ||
| ghost const B: AutoInit := 15 | ||
|
|
||
| const g: Nonempty // error: requires initialization | ||
| const g: Nonempty | ||
| const h: Nonempty := 15 | ||
| ghost const G: Nonempty | ||
| ghost const H: Nonempty := 15 | ||
|
|
||
| const s: PossiblyEmpty // error: requires initialization | ||
| const s: PossiblyEmpty | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's possibly the biggest potential issue but I think we are fine, since a trait is a collection of contracts, and someone should at least extend a mocked class that extends these contracts to test them. |
||
| const t: PossiblyEmpty := 15 | ||
| ghost const S: PossiblyEmpty // error: requires initialization | ||
| ghost const S: PossiblyEmpty | ||
| ghost const T: PossiblyEmpty := 15 | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Allow value traits (those that do not extend from object), to declare const fields without initializers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, could you use the most generic version so that you can also test for newtypes?