From 8f18456b7e89412855abc9993447512bdb835da9 Mon Sep 17 00:00:00 2001 From: Rustan Leino Date: Thu, 16 Jul 2015 15:37:50 -0700 Subject: Fixed bugs in the parsing of explicit type arguments. Fixed resolution bug where some type arguments were not checked to have been determined. Fixed resolution bugs where checking for equality-supporting types was missing. --- Test/dafny0/EqualityTypes.dfy | 112 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) (limited to 'Test/dafny0/EqualityTypes.dfy') diff --git a/Test/dafny0/EqualityTypes.dfy b/Test/dafny0/EqualityTypes.dfy index b2812759..c510cfb1 100644 --- a/Test/dafny0/EqualityTypes.dfy +++ b/Test/dafny0/EqualityTypes.dfy @@ -241,3 +241,115 @@ module Deep { var m1 := map[ko := 5]; // error: bad type } } + +//-------------------------- + +module UnderspecifiedTypeParameters { + method UP() + function method UG(): int + method Callee() + class TakesParam { } + + method MPG() + { + var g := UG(); // error: type parameter underspecified + UP(); // error: type parameter underspecified + } + method M() { + var zs: set; // error: type is underspecified + Callee<(int)>(); + Callee(); // error: type is underspecified + Callee<()>(); + // The following + Callee(); // error: type is underspecified + } +} + +module EqualitySupportingTypes { + method P() + function method G(): int + class AClass { + static function method H(): bool + static method Q() + } + + method Callee() + function method FCallee(): T + + datatype Dt = Dt(f: int -> int) + codatatype Stream = Cons(T, Stream) + + method M() + { + Callee
(); // error: Dt is not an equality-supporting type + Callee>(); // error: specified type does not support equality + + // set is allowed in a non-ghost context only if X is equality supporting. + // Ditto for multiset and map. + var s3x: set
; // error: this type not allowed in a non-ghost context + var is3x: iset
; // error: this type not allowed in a non-ghost context + var mast: multiset; // error: this type not allowed in a non-ghost context + var qt: seq>; // allowed + var mp0: map; // error: this type not allowed in a non-ghost context + var mp1: map; // allowed + var imp0: imap; // error: this type not allowed in a non-ghost context + var imp1: imap; // allowed + + var S := FCallee(); // this gives s:set + if 4 in S { // this constrains the type further to be s:set + } + + var xy: set>; + var xz: set>>; // error: set type argument must support equality + + Callee>>(); // bogus: a set shouldn't ever be allowed to take a Stream as an argument (this check seems to be missing for explicit type arguments) -- Note: language definition should be changed, because it doesn't make sense for it to talk about a type appearing in a ghost or non-ghost context. Instead, set/iset/multiset/map/imap should always be allowed to take any type argument, but these types may or may not support equality. + var xg := G>>(); + + var ac0: AClass; + var ac1: AClass,int>; // error: type parameter 0 is required to support equality + var ac2: AClass>; + var xd0 := ac0.H(); + var xd1 := ac1.H,real>(); // error (remnant of the fact that the type of ac1 is not allowed) + var xd2 := ac2.H>(); // error: type parameter 1 is required to support equality + var xe0 := ac0.H; + var xe1 := ac1.H,real>; // error (remnant of the fact that the type of ac1 is not allowed) + var xe2 := ac2.H>; // error: type parameter 1 is required to support equality + var xh0 := AClass.H(); + var xh1 := AClass.H,real>(); + var xh2 := AClass.H>(); // error: type parameter 1 is required to support equality + var xk0 := AClass.H; + var xk1 := AClass,real>.H; // error: class type param 0 wants an equality-supporting type + var xk2 := AClass>.H; + AClass,int>.Q(); // error: class type param 0 wants an equality-supporting type + AClass>.Q(); + AClass>.Q,real>(); + AClass>.Q>(); // error: method type param 1 wants an equality-supporting type + +/*************************** TESTS YET TO COME + var ac8: AClass; + var xd8 := (if 5/0 == 3 then ac0 else ac8).H(); // error: this should be checked by the verifier + + AClass>>.Q(); // error: cannot utter "set>" Or is that okay??? + AClass.Q>,real>(); // error: cannot utter "set>" Or is that okay??? + var xi0 := AClass>>.H(); // error: cannot utter "set>" Or is that okay??? + var xi1 := AClass.H>>(); // error: cannot utter "set>" Or is that okay??? + + var x, t, s: seq int>, fii: int -> int; + if s == t { + x := 5; // error: assigning to non-ghost variable in ghost context + } + if fii in s { + x := 4; // error: assigning to non-ghost variable in ghost context + } + if !(fii in s) { + x := 3; // error: assigning to non-ghost variable in ghost context + } + + ghost var ghostset: set> := {}; // fine, since this is ghost + forall u | 0 <= u < 100 + ensures var lets: set> := {}; lets == lets // this is ghost, so the equality requirement doesn't apply + { + } +*********************************************/ + } +} -- cgit v1.2.3