-
Notifications
You must be signed in to change notification settings - Fork 257
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
Fix: Recursive constant initialization was not checked if in constructor #2862
Open
MikaelMayer
wants to merge
21
commits into
master
Choose a base branch
from
fix-2727-soundness-constant
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0b34697
Fix: Recursive constant initialization was not checked if in constructor
MikaelMayer dd2ec2e
Update RELEASE_NOTES.md
MikaelMayer 75344fb
Added review comment use case and fixed the code
MikaelMayer b03a40a
Merge branch 'fix-2727-soundness-constant' of https://github.com/dafn…
MikaelMayer 4f7300f
Merge branch 'master' into fix-2727-soundness-constant
MikaelMayer f7e90a2
Better handling of alternatives
MikaelMayer 04eeb43
Refactoring
MikaelMayer a4d3a27
Merge branch 'fix-2727-soundness-constant' of https://github.com/dafn…
MikaelMayer 56dbf3b
Merge branch 'master' into fix-2727-soundness-constant
MikaelMayer 5568664
Fix CI
MikaelMayer bac8625
Merge branch 'master' into fix-2727-soundness-constant
MikaelMayer bd717d1
Create 2862.fix
MikaelMayer e956e87
Merge branch 'fix-2727-soundness-constant' of https://github.com/dafn…
MikaelMayer 0c20291
Merge branch 'master' into fix-2727-soundness-constant
MikaelMayer baa398f
Merge branch 'master' into fix-2727-soundness-constant
MikaelMayer 2e98a55
Prevent constants to be assigned twice
MikaelMayer f18254b
Merge branch 'master' into fix-2727-soundness-constant
MikaelMayer d7fd892
Merge branch 'master' into fix-2727-soundness-constant
MikaelMayer b53829c
Merge branch 'master' into fix-2727-soundness-constant
MikaelMayer 3ac8137
One more soundness fix
MikaelMayer 5555cde
One more soundness fix
MikaelMayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// RUN: %dafny_0 -compile:0 "%s" > "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
class Dummy { | ||
const i: int | ||
constructor(i: int) { | ||
this.i := i; | ||
} | ||
} | ||
|
||
class NoError { | ||
const a: int | ||
const a2: int | ||
const a3: int | ||
const b: int | ||
const c: int | ||
const d: Dummy | ||
const e: array<int> | ||
|
||
constructor() { | ||
a := 3; | ||
if a == 3 { | ||
a2 := 1; | ||
} else { | ||
a2 := 2; | ||
} | ||
match a2 { | ||
case 2 => | ||
a3 := a; | ||
case _ => | ||
a3 := a + 1; | ||
} | ||
b := a3 + 1; | ||
c := a2; | ||
d := new Dummy(c); | ||
e := new int[b]; | ||
} | ||
} | ||
|
||
class AlternativeError { | ||
const a: int | ||
const a2: int | ||
const b: int | ||
const b2: int | ||
|
||
constructor() { | ||
if true { | ||
a := 1; | ||
} | ||
b := a; // Error here | ||
match true { | ||
case true => | ||
a2 := 1; | ||
case false => | ||
} | ||
b2 := a2; // Error here | ||
} | ||
} | ||
|
||
class LoopError { | ||
const a: int | ||
const a2: int | ||
const a3: int | ||
const a4: int | ||
|
||
constructor() { | ||
while true { | ||
a := 1; // Error here | ||
} | ||
while { | ||
case true => | ||
a2 := 1; // Error here | ||
} | ||
if { | ||
case true => | ||
a3 := 1; // Error here | ||
} | ||
/*forall x: nat { | ||
a4 := 1; // Error here | ||
}*/ | ||
} | ||
} | ||
|
||
class SecondInitializationError { | ||
const a := b + b | ||
const b: int | ||
|
||
constructor (x: int) { | ||
var k := a; // Error here | ||
print a, "\n"; | ||
b := x; | ||
assert k == a; | ||
print a, "\n"; | ||
if k != a { | ||
var y := 5 / 0; | ||
} | ||
} | ||
} | ||
|
||
class RecursiveError { | ||
const a: int := b | ||
const b: int | ||
|
||
constructor () { | ||
b := a + 1; // Error here | ||
new; | ||
} | ||
} | ||
|
||
class MultipleAssignmentError { | ||
const b: int | ||
|
||
constructor () { | ||
b := 1; | ||
b := 2; // Error here | ||
new; | ||
} | ||
} | ||
|
||
|
||
method Main() { | ||
var c := new SecondInitializationError(5); | ||
var d := new RecursiveError(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
git-issue-2727.dfy(50,9): Error: Not all paths might have initialized the constant field a, which needs to be initialized at this point. | ||
git-issue-2727.dfy(56,10): Error: Not all paths might have initialized the constant field a2, which needs to be initialized at this point. | ||
git-issue-2727.dfy(68,6): Error: Cannot assign constant field in a loop statement. | ||
git-issue-2727.dfy(72,8): Error: Cannot assign constant field in a loop statement. | ||
git-issue-2727.dfy(76,8): Error: Cannot assign constant field in an alternative if-case statement. | ||
git-issue-2727.dfy(89,13): Error: Missing initialization of constant field through the dependency a -> b, which needs to be initialized at this point. | ||
git-issue-2727.dfy(90,10): Error: Missing initialization of constant field through the dependency a -> b, which needs to be initialized at this point. | ||
git-issue-2727.dfy(105,9): Error: Missing initialization of constant field through the dependency a -> b, which needs to be initialized at this point. | ||
git-issue-2727.dfy(115,4): Error: The constant b cannot be assigned twice. | ||
9 resolution/type errors detected in git-issue-2727.dfy |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I keep forgetting that these are called "pass", I'm always looking for "phase". Next time, if I forget again, I will be able to find them.