-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for disjunctive (“or”) patterns (#2448)
feat: Add support for disjunctive (“or”) patterns * `Source/Dafny/AST/DafnyAst.cs` (`DisjunctivePattern`): New subclass of `ExtendedPattern`. (`IsWildcardPattern`): New property. * `Source/Dafny/AST/Printer.cs` (`PrintExtendedPattern`): Add support for disjunctive patterns. * `Source/Dafny/Cloner.cs` (`CloneExtendedPattern`): Refactor, add support for disjunctive patterns. * `Source/Dafny/Dafny.atg` (`ExtendedPattern`): Rename to `SingleExtendedPattern`. (`ExtendedPattern`): New production for `|`-separated patterns. * `Source/Dafny/Resolver.cs` (`FreshTempVarName`): Refactor, remove obsolete comment. * `Source/Dafny/Resolver.cs` (`RBranch`, `RBranchStmt`): Reject disjunctive patterns. (`RemoveIllegalSubpatterns`): New function to detect, report, and remove nested disjunctive patterns and variables in disjunctive patterns. (`FlattenDisjunctivePatterns`): New function to convert a single `DisjunctivePattern` into one extended pattern per alternative. (`FlattenNestedMatchCaseExpr`): New wrapper around `FlattenDisjunctivePatterns` for `NestedMatchCaseExpr`. (`CompileNestedMatchExpr`): Use it. (`FlattenNestedMatchCaseStmt`): New wrappers around `FlattenDisjunctivePatterns` for `NestedMatchCaseStmt`. (`CompileNestedMatchStmt`): Use it. (`CheckLinearExtendedPattern`): Check the branches of each disjunctive pattern separately. Match bodies are not cloned because they are already resolved; see #2334 for details. Closes #2220.
- Loading branch information
1 parent
64c21e6
commit a47f0c0
Showing
11 changed files
with
254 additions
and
48 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// RUN: %dafny_0 /compile:0 "%s" > "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
module SanityChecks { | ||
datatype T = A(int) | B(nat) | C(bool) | ||
|
||
method Variables(t: T) { | ||
match t | ||
case A(n) // Error: Or-patterns may not bind variables | ||
| B(n) => // Error: Or-patterns may not bind variables | ||
case _ => | ||
} | ||
|
||
method Nesting(t: T) { | ||
match t | ||
case A(1 | 2 | _) => // Error: Or-patterns are not allowed inside other patterns | ||
case B(0 | _) // Error: Or-patterns are not allowed inside other patterns | ||
| C(_ | _ | _) => // Error: Or-patterns are not allowed inside other patterns | ||
} | ||
} |
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,6 @@ | ||
OrPatternErrors.dfy(9,13): Error: Disjunctive patterns may not bind variables | ||
OrPatternErrors.dfy(10,13): Error: Disjunctive patterns may not bind variables | ||
OrPatternErrors.dfy(16,13): Error: Disjunctive patterns are not allowed inside other patterns | ||
OrPatternErrors.dfy(17,13): Error: Disjunctive patterns are not allowed inside other patterns | ||
OrPatternErrors.dfy(18,13): Error: Disjunctive patterns are not allowed inside other patterns | ||
5 resolution/type errors detected in OrPatternErrors.dfy |
Oops, something went wrong.