summaryrefslogtreecommitdiff
path: root/Source/Dafny/Resolver.cs
diff options
context:
space:
mode:
authorGravatar Rustan Leino <unknown>2014-05-07 16:13:15 -0700
committerGravatar Rustan Leino <unknown>2014-05-07 16:13:15 -0700
commitdc0a9130355352d0f47e07232d8119fc7219ccbc (patch)
tree92e271f15a1bfc2ba37c7e5b5e7ccfe2cd9612a7 /Source/Dafny/Resolver.cs
parentda70d7149e435bfc83962b3814bc173840b5006f (diff)
Fixed bug in resolution, where type proxies involved in equality tests did not get assigned. (Issue #35)
Fixed Main detection--a method "Main" with type parameters cannot be a program entry point.
Diffstat (limited to 'Source/Dafny/Resolver.cs')
-rw-r--r--Source/Dafny/Resolver.cs19
1 files changed, 15 insertions, 4 deletions
diff --git a/Source/Dafny/Resolver.cs b/Source/Dafny/Resolver.cs
index 82844d56..44351754 100644
--- a/Source/Dafny/Resolver.cs
+++ b/Source/Dafny/Resolver.cs
@@ -6145,10 +6145,21 @@ namespace Microsoft.Dafny
case BinaryExpr.Opcode.Eq:
case BinaryExpr.Opcode.Neq:
- if (!ComparableTypes(e.E0.Type, e.E1.Type)) {
- if (!UnifyTypes(e.E0.Type, e.E1.Type)) {
- Error(expr, "arguments must have the same type (got {0} and {1})", e.E0.Type, e.E1.Type);
- }
+ // We will both check for comparability and attempt to unify the types, and we do them in this order so that
+ // the compatibility check is not influenced by the unification.
+ var areComparable = ComparableTypes(e.E0.Type, e.E1.Type);
+ var unificationSuccess = UnifyTypes(e.E0.Type, e.E1.Type);
+ if (areComparable) {
+ // The expression is legal. For example, we may have received two equal types, or we have have gotten types like
+ // array<T> and array<U> where T is a type parameter and U is some type.
+ // Still, we're still happy that we did the type unification to assign type proxies as needed.
+ } else if (unificationSuccess) {
+ // The expression is legal. This can happen if one of the types contains a type proxy. For example, if the
+ // first type is array<T> and the second type is a proxy, then the compatibility check will return false but
+ // unification will succeed.
+ } else {
+ // The types are not comparable and do not unify. It's time for an error message.
+ Error(expr, "arguments must have the same type (got {0} and {1})", e.E0.Type, e.E1.Type);
}
expr.Type = Type.Bool;
break;