diff options
author | qunyanm <unknown> | 2016-01-08 11:08:12 -0800 |
---|---|---|
committer | qunyanm <unknown> | 2016-01-08 11:08:12 -0800 |
commit | 44b30341ed42c5348e860bb52c1940891068002b (patch) | |
tree | 449268bc16b89fc685a426e7e03ba88cd815de38 | |
parent | 4c4647bbd61883edee6f55d5dc37c9649d23af2e (diff) |
Fix issue 117. Generate an error when the "opened" of an import doesn't match
between a module and its refinement base.
-rw-r--r-- | Source/Dafny/RefinementTransformer.cs | 21 | ||||
-rw-r--r-- | Test/dafny4/Bug117.dfy | 37 | ||||
-rw-r--r-- | Test/dafny4/Bug117.dfy.expect | 3 |
3 files changed, 61 insertions, 0 deletions
diff --git a/Source/Dafny/RefinementTransformer.cs b/Source/Dafny/RefinementTransformer.cs index 82ddddf1..6281417d 100644 --- a/Source/Dafny/RefinementTransformer.cs +++ b/Source/Dafny/RefinementTransformer.cs @@ -88,6 +88,27 @@ namespace Microsoft.Dafny "no more than one exclusive refinement may exist for a given module.");
}
}
+ // check that the openess in the imports between refinement and its base matches
+ List<TopLevelDecl> declarations = m.TopLevelDecls;
+ List<TopLevelDecl> baseDeclarations = m.RefinementBase.TopLevelDecls;
+ foreach (var im in declarations) {
+ if (im is ModuleDecl) {
+ ModuleDecl mdecl = (ModuleDecl)im;
+ //find the matching import from the base
+ foreach (var bim in baseDeclarations) {
+ if (bim is ModuleDecl && ((ModuleDecl)bim).Name.Equals(mdecl.Name)) {
+ if (mdecl.Opened != ((ModuleDecl)bim).Opened) {
+ string message = mdecl.Opened ?
+ "{0} in {1} cannot be imported with \"opened\" because it does not match the corresponding import in the refinement base {2} " :
+ "{0} in {1} must be imported with \"opened\" to match the corresponding import in its refinement base {2}.";
+ reporter.Error(MessageSource.RefinementTransformer,m.tok, message, im.Name, m.Name, m.RefinementBase.Name);
+ }
+ break;
+ }
+ }
+ }
+ }
+
PreResolveWorker(m);
} else {
reporter.Error(MessageSource.RefinementTransformer, m.RefinementBaseName[0], "module ({0}) named as refinement base is not a literal module or simple reference to a literal module", Util.Comma(".", m.RefinementBaseName, x => x.val));
diff --git a/Test/dafny4/Bug117.dfy b/Test/dafny4/Bug117.dfy new file mode 100644 index 00000000..2ae4bc70 --- /dev/null +++ b/Test/dafny4/Bug117.dfy @@ -0,0 +1,37 @@ +// RUN: %dafny /compile:0 "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+abstract module AbstractModule1
+{
+ type AbstractType1
+}
+
+abstract module AbstractModule2
+{
+ import opened AM1 as AbstractModule1
+
+ datatype AbstractType2 = AbstractType2(x:AbstractType1)
+}
+
+abstract module AbstractModule3
+{
+ import AM1 as AbstractModule1
+
+ datatype AbstractType2 = AbstractType2(x:AM1.AbstractType1)
+}
+
+module ConcreteModule1
+{
+ type AbstractType1 = int
+}
+
+module ConcreteModule2 refines AbstractModule2
+{
+ import AM1 = ConcreteModule1 // error: must be declared "opened" to match AbstratctModule2
+}
+
+module ConcreteModule3 refines AbstractModule3
+{
+ import opened AM1 = ConcreteModule1 // error: can't be declared "opened" to match AbstractModule3
+}
+
diff --git a/Test/dafny4/Bug117.dfy.expect b/Test/dafny4/Bug117.dfy.expect new file mode 100644 index 00000000..0c5a5445 --- /dev/null +++ b/Test/dafny4/Bug117.dfy.expect @@ -0,0 +1,3 @@ +Bug117.dfy(28,7): Error: AM1 in ConcreteModule2 must be imported with "opened" to match the corresponding import in its refinement base AbstractModule2.
+Bug117.dfy(33,7): Error: AM1 in ConcreteModule3 cannot be imported with "opened" because it does not match the corresponding import in the refinement base AbstractModule3
+2 resolution/type errors detected in Bug117.dfy
|