-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correct parsing rules for loop invariants (#214)
- Loading branch information
Showing
13 changed files
with
448 additions
and
14 deletions.
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
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,7 @@ | ||
package org.move.lang.core.psi.ext | ||
|
||
import org.move.lang.core.psi.MvExpr | ||
import org.move.lang.core.psi.MvForIterCondition | ||
|
||
val MvForIterCondition.expr: MvExpr? get() = exprList.firstOrNull() | ||
val MvForIterCondition.specExpr: MvExpr? get() = exprList.drop(1).firstOrNull() |
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
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
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
25 changes: 25 additions & 0 deletions
25
src/test/resources/org/move/lang/parser/complete/loop_invariants.move
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,25 @@ | ||
module 0x1::loop_invariants { | ||
fun main() { | ||
while (true) {} spec { assert true }; | ||
while (true) 1 + 1 spec { assert true }; | ||
// loop invariant is written in a spec block inside the loop condition | ||
while ({spec {assert x < 42;}; n < 64}) { | ||
spec { | ||
assert x > 42; | ||
assert 0 < x; | ||
}; | ||
n = n + 1 | ||
}; | ||
|
||
// the following should parse successfully but fail typing | ||
spec {} + 1; | ||
spec {} && spec {}; | ||
&mut spec {}; | ||
(spec {}: ()); | ||
|
||
for (i in 1..10 spec { assert true }) {}; | ||
for (i in 0..1 spec {invariant y > 0;}) { | ||
y = y + 1; | ||
}; | ||
} | ||
} |
Oops, something went wrong.