Skip to content
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

Implements an {:expect} attribute on an assert statement, which makes it compiled, if not ghost, as well as verified #3458

Closed
wants to merge 189 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
97ac9b6
Adding quicktest
Jan 29, 2021
87f0eee
Edit per comment from Remy
Jul 14, 2022
848ae6b
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 14, 2022
4194195
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 14, 2022
9b54f5f
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 14, 2022
be99f87
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 14, 2022
c706f5d
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 15, 2022
63e22eb
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 15, 2022
22d7433
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 15, 2022
78c577d
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 15, 2022
5795f9f
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 19, 2022
044c107
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 19, 2022
69e27cf
Merge branch 'master' into cok-quicktest
davidcok Jul 20, 2022
f42c745
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 20, 2022
9e92bd8
Merge branch 'master' into cok-quicktest
davidcok Jul 20, 2022
92825dc
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 20, 2022
e201a77
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 21, 2022
e02d6ce
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 22, 2022
0465b15
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 22, 2022
68f52ce
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 22, 2022
fe933e2
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 22, 2022
6f34117
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 22, 2022
c396e83
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jul 27, 2022
433c824
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 10, 2022
82c8060
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 11, 2022
7859237
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 15, 2022
8bd7d03
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 16, 2022
42be55b
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 17, 2022
7ef5288
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 18, 2022
98c5e41
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 18, 2022
9f1e92c
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 21, 2022
d78800a
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 24, 2022
dc2f742
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 25, 2022
8b4e194
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 25, 2022
c292bae
Merge branch 'master' of https://github.com/dafny-lang/dafny
Aug 26, 2022
50702f8
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 1, 2022
c49f8a3
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 1, 2022
9c68747
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 1, 2022
aee08f5
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 2, 2022
6bba113
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 2, 2022
032e12a
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 6, 2022
e11fd63
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 7, 2022
24921df
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 14, 2022
2e3a81f
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 18, 2022
91e05eb
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 20, 2022
ba9f954
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 21, 2022
47815c1
Checking included files
Sep 21, 2022
956e476
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 24, 2022
5aa1aa9
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 26, 2022
834cee3
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 27, 2022
f6b3d49
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 27, 2022
977b36a
Merge branch 'cok-quicktest' of https://github.com/davidcok/dafny
Sep 29, 2022
043986b
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 29, 2022
710f269
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 29, 2022
ea10461
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 29, 2022
09591e8
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 29, 2022
408f44e
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 29, 2022
02ffee4
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 29, 2022
c99fbe9
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 30, 2022
f4d4a02
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 30, 2022
448cb44
Merge branch 'master' of https://github.com/dafny-lang/dafny
Sep 30, 2022
a1e28fd
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 3, 2022
77f4e1f
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 4, 2022
c8dc66a
Link to snapshot for v3.9.0
Oct 4, 2022
30165e3
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 4, 2022
ad14c5c
Link to snapshot for v3.9.0
Oct 4, 2022
f9d72de
Link to snapshot for v3.9.0
Oct 4, 2022
a60dd9a
Fixing Snapshot file
Oct 5, 2022
c04d360
Some typos and workding changes
Oct 5, 2022
48ccd27
Edits to use the language of greatest predicates and greatest lemmas
Oct 5, 2022
f3ed37b
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 5, 2022
9a34972
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 6, 2022
4389f19
Conflict resolution
Oct 6, 2022
473be16
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 7, 2022
0559d39
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 7, 2022
23ed17e
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 25, 2022
b4a9a3b
Merge branch 'master' of https://github.com/dafny-lang/dafny
Oct 25, 2022
bd94cc5
Merge remote-tracking branch 'upstream/master'
Oct 28, 2022
ceb95b7
Merge remote-tracking branch 'upstream/master'
Oct 28, 2022
e7d5dea
Merge remote-tracking branch 'upstream/master'
Oct 28, 2022
b49eeda
Merge remote-tracking branch 'upstream/master'
Oct 29, 2022
ef86f34
Merge remote-tracking branch 'upstream/master'
Nov 3, 2022
12a7f03
Merge remote-tracking branch 'upstream/master'
Nov 4, 2022
bfab006
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 7, 2022
d4deeb6
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 8, 2022
f12cc28
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 18, 2022
6820ca2
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 18, 2022
9d3411f
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 20, 2022
5bd3845
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 21, 2022
b548d41
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 21, 2022
ae1e30c
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 21, 2022
b527539
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 21, 2022
0713e90
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 23, 2022
f1e788e
just touching
Nov 28, 2022
4510b5d
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 29, 2022
a07d7a1
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 29, 2022
48455cc
Spurious edit on master
Nov 30, 2022
125c70e
Merge branch 'master' of https://github.com/dafny-lang/dafny
Nov 30, 2022
1fd6798
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 1, 2022
1c47231
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 2, 2022
f757e02
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 2, 2022
266e045
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 8, 2022
56b04e5
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 9, 2022
57c7af0
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 9, 2022
85be9ee
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 12, 2022
be76074
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 13, 2022
c8fed8b
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 14, 2022
9eee8f1
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 15, 2022
29864c7
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 15, 2022
94970bb
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 16, 2022
d72c416
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 16, 2022
9ef66f0
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 16, 2022
d0a57a9
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 20, 2022
917c5b9
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 20, 2022
4b7b4ed
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 21, 2022
8008caa
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 21, 2022
26eca7f
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 21, 2022
06930ef
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 21, 2022
271c77b
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 22, 2022
f3ce788
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 22, 2022
5485716
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 22, 2022
4096c4c
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 22, 2022
a3d9f25
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 22, 2022
e76a535
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 22, 2022
04c0277
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 23, 2022
22a34bd
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 23, 2022
a90bfb9
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 23, 2022
07ec7ec
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 23, 2022
46b373e
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 23, 2022
6e86c02
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 23, 2022
2a105e3
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 27, 2022
dd74785
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 27, 2022
d44975e
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 28, 2022
5b5f6ea
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 29, 2022
d154427
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 29, 2022
a1fd105
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 30, 2022
29af14d
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 30, 2022
a322ff5
Merge branch 'master' of https://github.com/dafny-lang/dafny
Dec 31, 2022
7091bdd
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 2, 2023
f62aeab
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 3, 2023
6f30d24
RUnning nightly-tests only on main repo
Jan 4, 2023
ab590c1
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 4, 2023
e8784ea
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 4, 2023
4ea5f26
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 6, 2023
9cb7aae
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 8, 2023
6a3706d
fix: Specify Python version in the integration tests (#3340)
fabiomadge Jan 8, 2023
9b05c3f
chore: Remove final `set-output` (#3342)
fabiomadge Jan 9, 2023
83f2282
Documentation snapshot for V3.10.0 (#3208)
davidcok Jan 9, 2023
2082ca0
Initial C# port of auditor (#3175)
atomb Jan 9, 2023
5bf62da
Improve Z3 detection (#3233)
atomb Jan 9, 2023
8ce274f
Add a missing expression clone (#3346)
atomb Jan 10, 2023
ea164ef
Use %diff instead of diff for test (#3349)
atomb Jan 10, 2023
6fd8891
Add missing release notes (#3335)
keyboardDrummer Jan 10, 2023
aa4f204
Fix: Other CLI files that are not found do not trigger exceptions (#3…
MikaelMayer Jan 12, 2023
e878202
Cok retry induction tests (#3307)
davidcok Jan 12, 2023
a472528
Documenting compilation errors (#3341)
davidcok Jan 12, 2023
9811ada
Revert "Cok retry induction tests (#3307)" (#3364)
keyboardDrummer Jan 13, 2023
60b6c66
Jar files, both library and executable, are now created as part of bu…
davidcok Jan 16, 2023
bb84559
Do not fail the deep test check on in progress runs (#3363)
keyboardDrummer Jan 17, 2023
a19f44c
Enable passing a percentage as a value for --cores (#3357)
keyboardDrummer Jan 17, 2023
a2fbc0e
Fix: Proper warning that 'new' cannot be used in expressions, instead…
MikaelMayer Jan 18, 2023
56a6565
Merge conflicts
Jan 17, 2023
df7c8d0
Merge conflict
Jan 17, 2023
5448b35
Link to snapshot for v3.9.0
Oct 4, 2022
f11e7d0
Merge remote-tracking branch 'upstream/master'
Jan 20, 2023
5a0a032
FIxing diffs to upstream
Jan 20, 2023
0464a88
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 23, 2023
48e1a83
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 24, 2023
7aea103
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 24, 2023
1b3fb64
Merge branch 'master' of https://github.com/davidcok/dafny
Jan 24, 2023
42a99ef
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 25, 2023
01de15d
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 31, 2023
101a0d1
Merge branch 'master' of https://github.com/davidcok/dafny
Jan 31, 2023
8f1fa1d
Merge branch 'master' of https://github.com/dafny-lang/dafny
Jan 31, 2023
66b628f
Merge branch 'master' of https://github.com/dafny-lang/dafny
Feb 1, 2023
cec9d52
Merge branch 'master' of https://github.com/davidcok/dafny
Feb 1, 2023
62b0c59
Merge branch 'master' of https://github.com/dafny-lang/dafny
Feb 1, 2023
8d8ee67
Merge branch 'master' of https://github.com/dafny-lang/dafny
Feb 2, 2023
47a5f5c
Merge branch 'master' of https://github.com/dafny-lang/dafny
Feb 3, 2023
b6201ab
Merge branch 'master' of https://github.com/dafny-lang/dafny
Feb 3, 2023
9b9202e
Merge branch 'master' of https://github.com/dafny-lang/dafny
Feb 3, 2023
aa8672c
Merge branch 'master' of https://github.com/dafny-lang/dafny
Feb 4, 2023
290a574
Implementation and new tests
Feb 4, 2023
157bc22
Implementing an optional argument for the :expect attribute
Feb 4, 2023
0fd8646
Adding a news release
Feb 4, 2023
774fc6a
Fixing a crash in Java
Feb 5, 2023
70e7a65
Update docs/DafnyRef/Statements.md
davidcok Feb 5, 2023
52ec29f
Fixing a test
Feb 5, 2023
9660410
Merge branch 'cok-3410-assert-expect' of https://github.com/davidcok/…
Feb 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implementing an optional argument for the :expect attribute
  • Loading branch information
davidcok committed Feb 4, 2023
commit 157bc227eb5370d6a2b83f306524cdb8707edca6
3 changes: 2 additions & 1 deletion Source/DafnyCore/AST/Statements/ExpectStmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.Dafny;

public class ExpectStmt : PredicateStmt, ICloneable<ExpectStmt> {
public static string DefaultMessage = "expectation violation";
public Expression Message;

public ExpectStmt Clone(Cloner cloner) {
Expand Down Expand Up @@ -32,4 +33,4 @@ public ExpectStmt(RangeToken rangeToken, Expression expr, Expression message, At
}
}
}
}
}
3 changes: 2 additions & 1 deletion Source/DafnyCore/Compilers/SinglePassCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3066,7 +3066,8 @@ public class CheckHasNoAssumes_Visitor : BottomUpVisitor {
expr = expectStmt.Expr;
} else {
var assertStmt = (AssertStmt)stmt;
msg = new StringLiteralExpr(stmt.Tok, "expectation violation", false);
var expectAttr = Attributes.Find(stmt.Attributes, "expect");
msg = expectAttr.Args.Count > 0 ? expectAttr.Args[0] : new StringLiteralExpr(expectAttr.Tok, ExpectStmt.DefaultMessage, false);
expr = assertStmt.Expr;
}
// TODO there's potential here to use target-language specific features such as exceptions
Expand Down
36 changes: 20 additions & 16 deletions Source/DafnyCore/Resolver/GhostInterestVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,33 @@ class GhostInterestVisitor {
Contract.Assume(!codeContext.IsGhost || mustBeErasable); // (this is really a precondition) CodeContext.IsGhost ==> mustBeErasable
Contract.Assume(mustBeErasable || proofContext == null); // (this is really a precondition) !mustBeErasable ==> proofContext == null

if ((stmt is AssertStmt && !Attributes.Contains(stmt.Attributes, "expect")) || stmt is AssumeStmt) {
if (stmt is AssumeStmt) {
stmt.IsGhost = true;

} else if (stmt is AssertStmt) {
var expectAttr = Attributes.Find(stmt.Attributes, "expect");
stmt.IsGhost = expectAttr == null;
var assertStmt = stmt as AssertStmt;
if (assertStmt != null && assertStmt.Proof != null) {
Visit(assertStmt.Proof, true, "an assert-by body");
}

} else if (stmt is ExpectStmt || (stmt is AssertStmt && Attributes.Contains(stmt.Attributes, "expect"))) {
stmt.IsGhost = false;
Expression msg;
Expression expr;
if (stmt is ExpectStmt) {
var expectStmt = (ExpectStmt)stmt;
msg = expectStmt.Message;
expr = expectStmt.Expr;
} else {
var assertStmt = (AssertStmt)stmt;
if (assertStmt.Proof != null) {
Visit(assertStmt.Proof, true, "an assert-by body");
if (expectAttr != null) {
if (mustBeErasable) {
Error(stmt, "assert with {{:expect}} statement is not allowed in this context (because this is a ghost method or because the statement is guarded by a specification-only expression)");
} else {
Expression expr = assertStmt.Expr;
Expression msg = expectAttr.Args.Count > 0 ? expectAttr.Args[0] : new StringLiteralExpr(expectAttr.Tok, ExpectStmt.DefaultMessage, false);
ExpressionTester.CheckIsCompilable(resolver, reporter, expr, codeContext);
Contract.Assert(msg != null);
ExpressionTester.CheckIsCompilable(resolver, reporter, msg, codeContext);
}
msg = new StringLiteralExpr(assertStmt.Tok, "expectation violation", false);
expr = assertStmt.Expr;
}

} else if (stmt is ExpectStmt) {
stmt.IsGhost = false;
var expectStmt = (ExpectStmt)stmt;
Expression msg = expectStmt.Message;
Expression expr = expectStmt.Expr;
if (mustBeErasable) {
Error(stmt, "expect statement is not allowed in this context (because this is a ghost method or because the statement is guarded by a specification-only expression)");
} else {
Expand Down
10 changes: 9 additions & 1 deletion Source/DafnyCore/Resolver/NameResolutionAndTypeInference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4384,10 +4384,18 @@ public XConstraint_EquatableArg(IToken tok, Type a, Type b, bool allowSuperSub,
enclosingStatementLabels = prevLblStmts;
loopStack = prevLoopStack;
}
if (assertStmt != null) {
var attr = Attributes.Find(assertStmt.Attributes, "expect");
if (attr != null) {
if (attr.Args.Count > 1) {
reporter.Error(MessageSource.Resolver, attr.tok, ":expect attribute may have at most one argument");
}
}
}
var expectStmt = stmt as ExpectStmt;
if (expectStmt != null) {
if (expectStmt.Message == null) {
expectStmt.Message = new StringLiteralExpr(s.Tok, "expectation violation", false);
expectStmt.Message = new StringLiteralExpr(s.Tok, ExpectStmt.DefaultMessage, false);
}
ResolveExpression(expectStmt.Message, resolutionContext);
Contract.Assert(expectStmt.Message.Type != null); // follows from postcondition of ResolveExpression
Expand Down
9 changes: 9 additions & 0 deletions Test/git-issues/git-issue-3410/git-issue-3410f.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ method Main() {
assert {:expect} i == 41;
print "Done\n";
}

method m() {
ghost var b: bool := true;
if b { assert {:expect} true; }
}

ghost method mm() {
assert {:expect} true;
}
4 changes: 3 additions & 1 deletion Test/git-issues/git-issue-3410/git-issue-3410f.dfy.expect
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
git-issue-3410f.dfy(6,19): Error: ghost variables such as i are allowed only in specification contexts. i was inferred to be ghost based on its declaration or initialization.
1 resolution/type errors detected in git-issue-3410f.dfy
git-issue-3410f.dfy(12,9): Error: assert with {:expect} statement is not allowed in this context (because this is a ghost method or because the statement is guarded by a specification-only expression)
git-issue-3410f.dfy(16,2): Error: assert with {:expect} statement is not allowed in this context (because this is a ghost method or because the statement is guarded by a specification-only expression)
3 resolution/type errors detected in git-issue-3410f.dfy
7 changes: 7 additions & 0 deletions Test/git-issues/git-issue-3410/git-issue-3410g.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %exits-with 2 %baredafny resolve --use-basename-for-filename "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

method m() {
assert {:expect "",""} true;
assert {:expect 10} true;
}
2 changes: 2 additions & 0 deletions Test/git-issues/git-issue-3410/git-issue-3410g.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git-issue-3410g.dfy(5,11): Error: :expect attribute may have at most one argument
1 resolution/type errors detected in git-issue-3410g.dfy
8 changes: 8 additions & 0 deletions Test/git-issues/git-issue-3410/git-issue-3410h.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %exits-with 1 %baredafny run --no-verify --use-basename-for-filename "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

method Main() {
var i: int := 42;
assert {:expect "expecting 42" } i == 41;
print "Done\n";
}
3 changes: 3 additions & 0 deletions Test/git-issues/git-issue-3410/git-issue-3410h.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Dafny program verifier did not attempt verification
[Program halted] git-issue-3410h.dfy(6,2): expecting 42
8 changes: 8 additions & 0 deletions Test/git-issues/git-issue-3410/git-issue-3410k.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %exits-with 1 %baredafny run --no-verify --use-basename-for-filename "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

method Main() {
var i: int := 42;
assert {:expect i } i == 41;
print "Done\n";
}
3 changes: 3 additions & 0 deletions Test/git-issues/git-issue-3410/git-issue-3410k.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Dafny program verifier did not attempt verification
[Program halted] git-issue-3410k.dfy(6,2): 42
5 changes: 5 additions & 0 deletions docs/DafnyRef/Attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,11 @@ method doSplitHere(x: bool) returns (y: int) {
### 23.3.3. `{:subsumption n}`
Overrides the `/subsumption` command-line setting for this assertion.

### 23.3.4. `{:expect s}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future, it seems like we could also support adding this to other specification contexts like requires, ensures, invariant, etc. (although see my independent question about whether this is the name we want)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite my slack comment, I see your point. I'm open to any naming, but making it anything other than an attribute would be more work and harder to generalize.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On thinking about it more I like using a {:checked} attribute. I think that terminology fits in well with the documentation for the related --test-assumptions option (in fact I even wonder if the option should be check-assumptions to avoid implying it's strongly coupled to dafny test.

We could think of expect P; as a short form for assume {:checked} P; (that's actually allowed when compiling).

Interested in @atomb's option here too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about {:check} to match assert, assume, expect as active present tense verbs.

Copy link
Member

@robin-aws robin-aws Feb 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thought: perhaps it would be better if expect itself behaved this way. That is, if it had to be both verified and checked at runtime. We could change this for Dafny 4.0.

I submit that even when writing a {:test} in Dafny, you almost always believe the expression you're expect-ing to be true. Tests often look a lot like examples, and examples in Dafny should verify as well, i.e. if you can't satisfy the precondition of the function you're trying to call, it's often an indication the specified interface of the code you're testing is wrong or too weak/strong.

We would also allow expect {:axiom} P; just like assert {:axiom} P;, for easy backwards compatibility and those times it's too much work to prove P. :- expect {:axiom} ... as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seebees I'm curious whether what I'm saying above jives with your more substantial experience than mine in using expect in Dafny tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the set of contracts currently supported, --check-assumptions would be a nice improvement on naming. However, I worry it might be confusing if we extend it to evaluate other contracts at runtime, including those that, at least in principle, might be verified. What do others think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note there is deeper discussion happening on the issue now, so we should move further replies there: #3410 (comment)

This attribute is recognized on an assert statement. If present, the statement's expression is both checked by the verifier and
is compiled to a run-time test (like an expect statement). The optional argument of the attribute is used as
the optional message provided by the equivalent expect statement.

## 23.4. Attributes on variable declarations

### 23.4.1. `{:assumption}`
Expand Down
6 changes: 6 additions & 0 deletions docs/DafnyRef/Statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,12 @@ their purpose -- to assist in proving the given assertion -- is manifest in the

Examples of this form of assert are given in the section of the [`reveal`](#sec-reveal-statement) statement and in [_Different Styles of Proof_](http:https://leino.science/papers/krml276.html)

An assert statement recoognizes an optional attribute `{:expect}`. If present, the statement acts as an `expect` statement as well as an assert, with the same expression.
That is, the `assert {:expect}` statement will be iverified by the verifier and tested at runtime.
davidcok marked this conversation as resolved.
Show resolved Hide resolved
The `{:expect}` attribute may take an argument, which serves the same purpose as the
optional message in an [expect statement](#sec-expect-statement). If `{:expect}` is present, the tested expression may not be ghost, nor may the statement be in a ghost context.
An `assert {:expect} P;` is equivalent to `assert P; expect P;`, but avoids replicating an identical expression P.

## 20.17. Assume Statement {#sec-assume-statement}
````grammar
AssumeStmt =
Expand Down