-
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.
Merge branch 'fix-4823-general-traits-bug-extends' of https://github.…
…com/dafny-lang/dafny into fix-4823-general-traits-bug-extends
- Loading branch information
Showing
15 changed files
with
104 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Diagnostics.Contracts; | ||
|
||
namespace Microsoft.Dafny; | ||
|
||
public static class ExternExtensions { | ||
|
||
public static bool IsExtern(this IAttributeBearingDeclaration declaration, DafnyOptions options, out string/*?*/ qualification, out string/*?*/ name) { | ||
// ensures result==false ==> qualification == null && name == null | ||
Contract.Ensures(Contract.Result<bool>() || (Contract.ValueAtReturn(out qualification) == null && Contract.ValueAtReturn(out name) == null)); | ||
// ensures result==true ==> qualification != null ==> name != null | ||
Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out qualification) == null || Contract.ValueAtReturn(out name) != null); | ||
|
||
qualification = null; | ||
name = null; | ||
if (!options.DisallowExterns) { | ||
var externArgs = Attributes.FindExpressions(declaration.Attributes, "extern"); | ||
if (externArgs != null) { | ||
if (externArgs.Count == 0) { | ||
return true; | ||
} else if (externArgs.Count == 1 && externArgs[0] is StringLiteralExpr) { | ||
name = externArgs[0].AsStringLiteral(); | ||
return true; | ||
} else if (externArgs.Count == 2 && externArgs[0] is StringLiteralExpr && externArgs[1] is StringLiteralExpr) { | ||
qualification = externArgs[0].AsStringLiteral(); | ||
name = externArgs[1].AsStringLiteral(); | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
6 changes: 4 additions & 2 deletions
6
Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/replaceables/complex/user.dfy
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
6 changes: 5 additions & 1 deletion
6
Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/replaceables/complex/user.dfy.expect
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
|
||
Dafny program verifier finished with 10 verified, 0 errors | ||
Dafny program verifier finished with 4 verified, 0 errors | ||
|
||
Dafny program verifier finished with 5 verified, 0 errors | ||
|
||
Dafny program verifier finished with 1 verified, 0 errors | ||
|
||
Dafny program verifier finished with 10 verified, 0 errors |
23 changes: 23 additions & 0 deletions
23
Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/replaceables/externErrors.dfy
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,23 @@ | ||
// RUN: ! %run %s > %t | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
replaceable module {:extern "FooNameOverride"} Foo { | ||
method {:extern "ZazOverride1"} Zaz() returns (i: int) | ||
ensures i >= 2 | ||
} | ||
|
||
module {:extern "BarNameOverride1"} TwoErrors replaces Foo { | ||
// missing error on BarNameOverride2 | ||
method {:extern "BarNameOverride2", "ZazOverride2"} Zaz() returns (i: int) | ||
ensures i >= 2 | ||
} | ||
|
||
replaceable module {:extern "FaaNameOverride"} Faa { | ||
method {:extern "ZazOverride1"} Zaz() returns (i: int) | ||
ensures i >= 2 | ||
} | ||
|
||
module {:extern} NoErrors replaces Faa { | ||
method {:extern "ZazOverride2"} Zaz() returns (i: int) | ||
ensures i >= 2 | ||
} |
3 changes: 3 additions & 0 deletions
3
Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/replaceables/externErrors.dfy.expect
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,3 @@ | ||
|
||
Dafny program verifier finished with 0 verified, 0 errors | ||
externErrors.dfy(9,36): Error: inside a module that replaces another, {:extern} attributes may only be used without arguments |
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
4 changes: 1 addition & 3 deletions
4
...nTests/TestFiles/LitTests/LitTest/comp/replaceables/replaceableExecutionErrors.dfy.expect
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
|
||
Dafny program verifier finished with 4 verified, 0 errors | ||
replaceableExecutionErrors.dfy(20,7): Error: a replaceable module may only be replaced once Other replacing module: replaceableExecutionErrors.dfy(26,7) | ||
replaceableExecutionErrors.dfy(14,7): Error: a replaceable module may only be replaced once Other replacing module: replaceableExecutionErrors.dfy(26,7) | ||
Dafny program verifier finished with 1 verified, 0 errors | ||
replaceableExecutionErrors.dfy(4,19): Error: when producing executable code, replaceable modules must be replaced somewhere in the program. For example, `module NeverReplacedImpl replaces NeverReplaced { ... }` |
4 changes: 3 additions & 1 deletion
4
.../IntegrationTests/TestFiles/LitTests/LitTest/comp/replaceables/resolveManyReplacement.dfy
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
3 changes: 3 additions & 0 deletions
3
...ationTests/TestFiles/LitTests/LitTest/comp/replaceables/resolveManyReplacement.dfy.expect
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,3 @@ | ||
resolveManyReplacement.dfy(10,7): Error: a replaceable module may only be replaced once Other replacing module: resolveManyReplacement.dfy(15,7) | ||
resolveManyReplacement.dfy(15,7): Error: modules 'Replacement1' and 'Replacement2' both have CompileName 'FooModule' | ||
2 resolution/type errors detected in resolveManyReplacement.dfy |