summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar qunyanm <unknown>2015-04-17 15:22:24 -0700
committerGravatar qunyanm <unknown>2015-04-17 15:22:24 -0700
commitd248da33b7763b8c3b2ef75ece9612a45182e7b0 (patch)
treefc7d59235c8ec55510ea18d8be3b579b38c3a481
parente4419c2e8d5469787f997fbf0e74f9ef8383c140 (diff)
Fix issue #69. If we can't find a member in classMembers, search the static
members of the enclosing module or its imports.
-rw-r--r--Source/Dafny/Resolver.cs13
-rw-r--r--Test/dafny4/Bug69.dfy14
-rw-r--r--Test/dafny4/Bug69.dfy.expect2
3 files changed, 28 insertions, 1 deletions
diff --git a/Source/Dafny/Resolver.cs b/Source/Dafny/Resolver.cs
index b25b8cbe..7f198946 100644
--- a/Source/Dafny/Resolver.cs
+++ b/Source/Dafny/Resolver.cs
@@ -6109,7 +6109,18 @@ namespace Microsoft.Dafny
if (memberName == "_ctor") {
Error(tok, "{0} {1} does not have an anonymous constructor", kind, ctype.Name);
} else {
- Error(tok, "member {0} does not exist in {2} {1}", memberName, ctype.Name, kind);
+ // search the static members of the enclosing module or its imports
+ if (moduleInfo.StaticMembers.TryGetValue(memberName, out member)) {
+ Contract.Assert(member.IsStatic); // moduleInfo.StaticMembers is supposed to contain only static members of the module's implicit class _default
+ if (ReallyAmbiguousThing(ref member)) {
+ Error(tok, "The name {0} ambiguously refers to a static member in one of the modules {1} (try qualifying the member name with the module name)", memberName, ((AmbiguousMemberDecl)member).ModuleNames());
+ } else {
+ nptype = GetReceiverType(tok, member);
+ return member;
+ }
+ } else {
+ Error(tok, "member {0} does not exist in {2} {1}", memberName, ctype.Name, kind);
+ }
}
return null;
} else {
diff --git a/Test/dafny4/Bug69.dfy b/Test/dafny4/Bug69.dfy
new file mode 100644
index 00000000..638a897c
--- /dev/null
+++ b/Test/dafny4/Bug69.dfy
@@ -0,0 +1,14 @@
+// RUN: %dafny /compile:0 "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+module M1
+{
+ predicate X(i:int)
+}
+
+module M2
+{
+ import opened M1
+ predicate P(i:int) requires X(i) { true } // ok
+ predicate{:opaque} O(i:int) requires X(i) { true } // resolution/type error: X does not exist
+} \ No newline at end of file
diff --git a/Test/dafny4/Bug69.dfy.expect b/Test/dafny4/Bug69.dfy.expect
new file mode 100644
index 00000000..73ba063c
--- /dev/null
+++ b/Test/dafny4/Bug69.dfy.expect
@@ -0,0 +1,2 @@
+
+Dafny program verifier finished with 4 verified, 0 errors