summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Rustan Leino <unknown>2014-07-14 19:14:30 -0700
committerGravatar Rustan Leino <unknown>2014-07-14 19:14:30 -0700
commitfda7a92b1f8f2b1fd360aa2b52aa3ddb3c705127 (patch)
tree2d9b0bbbfbdd4f73d5d2ba617ce9c78fec8107e0
parent8041bef009e34bb3c5e81ffe7b906ae4347e85d3 (diff)
Support for type synonyms in refinements
Started allowing arbitrary types to have type parameters
-rw-r--r--Source/Dafny/Cloner.cs2
-rw-r--r--Source/Dafny/Dafny.atg19
-rw-r--r--Source/Dafny/DafnyAst.cs11
-rw-r--r--Source/Dafny/Parser.cs496
-rw-r--r--Source/Dafny/RefinementTransformer.cs17
-rw-r--r--Source/Dafny/Resolver.cs16
-rw-r--r--Source/Dafny/Translator.cs24
-rw-r--r--Test/dafny0/EqualityTypes.dfy.expect10
-rw-r--r--Test/dafny0/TypeInstantiations.dfy58
-rw-r--r--Test/dafny0/TypeInstantiations.dfy.expect13
10 files changed, 380 insertions, 286 deletions
diff --git a/Source/Dafny/Cloner.cs b/Source/Dafny/Cloner.cs
index 3c6fe107..ebc547fb 100644
--- a/Source/Dafny/Cloner.cs
+++ b/Source/Dafny/Cloner.cs
@@ -29,7 +29,7 @@ namespace Microsoft.Dafny
if (d is ArbitraryTypeDecl) {
var dd = (ArbitraryTypeDecl)d;
- return new ArbitraryTypeDecl(Tok(dd.tok), dd.Name, m, dd.EqualitySupport, CloneAttributes(dd.Attributes));
+ return new ArbitraryTypeDecl(Tok(dd.tok), dd.Name, m, dd.EqualitySupport, dd.TypeArgs.ConvertAll(CloneTypeParam), CloneAttributes(dd.Attributes));
} else if (d is TypeSynonymDecl) {
var dd = (TypeSynonymDecl)d;
var tps = dd.TypeArgs.ConvertAll(CloneTypeParam);
diff --git a/Source/Dafny/Dafny.atg b/Source/Dafny/Dafny.atg
index b42e0633..fb68df7a 100644
--- a/Source/Dafny/Dafny.atg
+++ b/Source/Dafny/Dafny.atg
@@ -397,19 +397,22 @@ OtherTypeDecl<ModuleDefinition/*!*/ module, out TopLevelDecl td>
= (. IToken/*!*/ id;
Attributes attrs = null;
var eqSupport = TypeParameter.EqualitySupportValue.Unspecified;
- List<TypeParameter> typeArgs;
+ var typeArgs = new List<TypeParameter>();
+ td = null;
Type ty;
.)
"type"
{ Attribute<ref attrs> }
- NoUSIdent<out id> (. td = null; .)
- [ "(" "==" ")" (. eqSupport = TypeParameter.EqualitySupportValue.Required; .)
- | (. typeArgs = new List<TypeParameter>(); .)
+ NoUSIdent<out id>
+ ( "(" "==" ")" (. eqSupport = TypeParameter.EqualitySupportValue.Required; .)
+ [ GenericParameters<typeArgs> ]
+ |
[ GenericParameters<typeArgs> ]
- "="
- Type<out ty> (. td = new TypeSynonymDecl(id, id.val, typeArgs, module, ty, attrs); .)
- ] (. if (td == null) {
- td = new ArbitraryTypeDecl(id, id.val, module, eqSupport, attrs);
+ [ "="
+ Type<out ty> (. td = new TypeSynonymDecl(id, id.val, typeArgs, module, ty, attrs); .)
+ ]
+ ) (. if (td == null) {
+ td = new ArbitraryTypeDecl(id, id.val, module, eqSupport, typeArgs, attrs);
}
.)
[ SYNC ";"
diff --git a/Source/Dafny/DafnyAst.cs b/Source/Dafny/DafnyAst.cs
index acdeae1b..36ffd3ec 100644
--- a/Source/Dafny/DafnyAst.cs
+++ b/Source/Dafny/DafnyAst.cs
@@ -752,6 +752,9 @@ namespace Microsoft.Dafny {
this.Path = new List<IToken>();
}
+ /// <summary>
+ /// This constructor constructs a resolved type parameter
+ /// </summary>
public UserDefinedType(TypeParameter tp)
: this(tp.tok, tp.Name, tp)
{
@@ -835,6 +838,9 @@ namespace Microsoft.Dafny {
i++;
}
return true;
+ } else if (ResolvedClass is TypeSynonymDecl) {
+ var t = (TypeSynonymDecl)ResolvedClass;
+ return t.Rhs.SupportsEquality;
} else if (ResolvedParam != null) {
return ResolvedParam.MustSupportEquality;
}
@@ -1923,11 +1929,12 @@ namespace Microsoft.Dafny {
Contract.Invariant(TheType != null && Name == TheType.Name);
}
- public ArbitraryTypeDecl(IToken tok, string name, ModuleDefinition module, TypeParameter.EqualitySupportValue equalitySupport, Attributes attributes)
- : base(tok, name, module, new List<TypeParameter>(), attributes) {
+ public ArbitraryTypeDecl(IToken tok, string name, ModuleDefinition module, TypeParameter.EqualitySupportValue equalitySupport, List<TypeParameter> typeArgs, Attributes attributes)
+ : base(tok, name, module, typeArgs, attributes) {
Contract.Requires(tok != null);
Contract.Requires(name != null);
Contract.Requires(module != null);
+ Contract.Requires(typeArgs != null);
TheType = new TypeParameter(tok, name, equalitySupport);
}
}
diff --git a/Source/Dafny/Parser.cs b/Source/Dafny/Parser.cs
index 7e98ff9a..6f5d8dc5 100644
--- a/Source/Dafny/Parser.cs
+++ b/Source/Dafny/Parser.cs
@@ -488,7 +488,8 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken/*!*/ id;
Attributes attrs = null;
var eqSupport = TypeParameter.EqualitySupportValue.Unspecified;
- List<TypeParameter> typeArgs;
+ var typeArgs = new List<TypeParameter>();
+ td = null;
Type ty;
Expect(32);
@@ -496,29 +497,30 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Attribute(ref attrs);
}
NoUSIdent(out id);
- td = null;
- if (la.kind == 11 || la.kind == 21 || la.kind == 38) {
- if (la.kind == 11) {
+ if (la.kind == 11) {
+ Get();
+ Expect(33);
+ Expect(12);
+ eqSupport = TypeParameter.EqualitySupportValue.Required;
+ if (la.kind == 38) {
+ GenericParameters(typeArgs);
+ }
+ } else if (StartOf(3)) {
+ if (la.kind == 38) {
+ GenericParameters(typeArgs);
+ }
+ if (la.kind == 21) {
Get();
- Expect(33);
- Expect(12);
- eqSupport = TypeParameter.EqualitySupportValue.Required;
- } else {
- typeArgs = new List<TypeParameter>();
- if (la.kind == 38) {
- GenericParameters(typeArgs);
- }
- Expect(21);
Type(out ty);
td = new TypeSynonymDecl(id, id.val, typeArgs, module, ty, attrs);
}
- }
+ } else SynErr(133);
if (td == null) {
- td = new ArbitraryTypeDecl(id, id.val, module, eqSupport, attrs);
+ td = new ArbitraryTypeDecl(id, id.val, module, eqSupport, typeArgs, attrs);
}
if (la.kind == 8) {
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(133); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(134); Get();}
Get();
}
}
@@ -547,7 +549,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken bodyStart = Token.NoToken;
IToken bodyEnd = Token.NoToken;
- while (!(la.kind == 0 || la.kind == 34)) {SynErr(134); Get();}
+ while (!(la.kind == 0 || la.kind == 34)) {SynErr(135); Get();}
Expect(34);
while (la.kind == 9) {
Attribute(ref attrs);
@@ -570,8 +572,8 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
} else if (la.kind == 37) {
Get();
signatureEllipsis = t; openParen = Token.NoToken;
- } else SynErr(135);
- while (StartOf(3)) {
+ } else SynErr(136);
+ while (StartOf(4)) {
IteratorSpec(reads, mod, decreases, req, ens, yieldReq, yieldEns, ref readsAttrs, ref modAttrs, ref decrAttrs);
}
if (la.kind == 9) {
@@ -608,10 +610,10 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
} else if (la.kind == 62 || la.kind == 63 || la.kind == 64) {
FunctionDecl(mmod, out f);
mm.Add(f);
- } else if (StartOf(4)) {
+ } else if (StartOf(5)) {
MethodDecl(mmod, allowConstructors, out m);
mm.Add(m);
- } else SynErr(136);
+ } else SynErr(137);
}
void Attribute(ref Attributes attrs) {
@@ -681,7 +683,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
}
}
- } else SynErr(137);
+ } else SynErr(138);
}
void GenericParameters(List<TypeParameter/*!*/>/*!*/ typeArgs) {
@@ -719,7 +721,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Attributes attrs = null;
IToken/*!*/ id; Type/*!*/ ty;
- while (!(la.kind == 0 || la.kind == 30)) {SynErr(138); Get();}
+ while (!(la.kind == 0 || la.kind == 30)) {SynErr(139); Get();}
Expect(30);
if (mmod.IsStatic) { SemErr(t, "fields cannot be declared 'static'"); }
@@ -733,7 +735,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
FIdentType(out id, out ty);
mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs));
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(139); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(140); Get();}
Expect(8);
}
@@ -779,7 +781,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Get();
signatureEllipsis = t;
openParen = Token.NoToken;
- } else SynErr(140);
+ } else SynErr(141);
} else if (la.kind == 63) {
Get();
isPredicate = true;
@@ -793,7 +795,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Attribute(ref attrs);
}
NoUSIdent(out id);
- if (StartOf(5)) {
+ if (StartOf(6)) {
if (la.kind == 38) {
GenericParameters(typeArgs);
}
@@ -808,7 +810,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Get();
signatureEllipsis = t;
openParen = Token.NoToken;
- } else SynErr(141);
+ } else SynErr(142);
} else if (la.kind == 64) {
Get();
isCoPredicate = true;
@@ -818,7 +820,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Attribute(ref attrs);
}
NoUSIdent(out id);
- if (StartOf(5)) {
+ if (StartOf(6)) {
if (la.kind == 38) {
GenericParameters(typeArgs);
}
@@ -833,10 +835,10 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Get();
signatureEllipsis = t;
openParen = Token.NoToken;
- } else SynErr(142);
- } else SynErr(143);
+ } else SynErr(143);
+ } else SynErr(144);
decreases = isCoPredicate ? null : new List<Expression/*!*/>();
- while (StartOf(6)) {
+ while (StartOf(7)) {
FunctionSpec(reqs, reads, ens, decreases);
}
if (la.kind == 9) {
@@ -885,7 +887,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken bodyStart = Token.NoToken;
IToken bodyEnd = Token.NoToken;
- while (!(StartOf(7))) {SynErr(144); Get();}
+ while (!(StartOf(8))) {SynErr(145); Get();}
if (la.kind == 40) {
Get();
} else if (la.kind == 41) {
@@ -907,7 +909,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
SemErr(t, "constructors are only allowed in classes");
}
- } else SynErr(145);
+ } else SynErr(146);
keywordToken = t;
if (isLemma) {
if (mmod.IsGhost) {
@@ -953,8 +955,8 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
} else if (la.kind == 37) {
Get();
signatureEllipsis = t; openParen = Token.NoToken;
- } else SynErr(146);
- while (StartOf(8)) {
+ } else SynErr(147);
+ while (StartOf(9)) {
MethodSpec(req, mod, ens, dec, ref decAttrs, ref modAttrs);
}
if (la.kind == 9) {
@@ -1006,7 +1008,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
void FormalsOptionalIds(List<Formal/*!*/>/*!*/ formals) {
Contract.Requires(cce.NonNullElements(formals)); IToken/*!*/ id; Type/*!*/ ty; string/*!*/ name; bool isGhost;
Expect(11);
- if (StartOf(9)) {
+ if (StartOf(10)) {
TypeIdentOptional(out id, out name, out ty, out isGhost);
formals.Add(new Formal(id, name, ty, true, isGhost));
while (la.kind == 31) {
@@ -1027,7 +1029,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
} else if (la.kind == 2) {
Get();
id = t;
- } else SynErr(147);
+ } else SynErr(148);
Expect(7);
Type(out ty);
}
@@ -1103,7 +1105,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Get();
isGhost = true;
}
- if (StartOf(10)) {
+ if (StartOf(11)) {
TypeAndToken(out id, out ty);
if (la.kind == 7) {
Get();
@@ -1121,7 +1123,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
id = t; name = id.val;
Expect(7);
Type(out ty);
- } else SynErr(148);
+ } else SynErr(149);
if (name != null) {
identName = name;
} else {
@@ -1215,7 +1217,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
case 11: {
Get();
tok = t; gt = new List<Type>();
- if (StartOf(10)) {
+ if (StartOf(11)) {
Type(out ty);
gt.Add(ty);
while (la.kind == 31) {
@@ -1240,7 +1242,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
ReferenceType(out tok, out ty);
break;
}
- default: SynErr(149); break;
+ default: SynErr(150); break;
}
}
@@ -1266,13 +1268,13 @@ List<MaybeFreeExpression/*!*/>/*!*/ yieldReq, List<MaybeFreeExpression/*!*/>/*!*
ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
Expression/*!*/ e; FrameExpression/*!*/ fe; bool isFree = false; bool isYield = false; Attributes ensAttrs = null;
- while (!(StartOf(11))) {SynErr(150); Get();}
+ while (!(StartOf(12))) {SynErr(151); Get();}
if (la.kind == 50) {
Get();
while (IsAttribute()) {
Attribute(ref readsAttrs);
}
- if (StartOf(12)) {
+ if (StartOf(13)) {
FrameExpression(out fe);
reads.Add(fe);
while (la.kind == 31) {
@@ -1281,14 +1283,14 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
reads.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(151); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(152); Get();}
Expect(8);
} else if (la.kind == 45) {
Get();
while (IsAttribute()) {
Attribute(ref modAttrs);
}
- if (StartOf(12)) {
+ if (StartOf(13)) {
FrameExpression(out fe);
mod.Add(fe);
while (la.kind == 31) {
@@ -1297,9 +1299,9 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
mod.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(152); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(153); Get();}
Expect(8);
- } else if (StartOf(13)) {
+ } else if (StartOf(14)) {
if (la.kind == 46) {
Get();
isFree = true;
@@ -1311,7 +1313,7 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
if (la.kind == 47) {
Get();
Expression(out e, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(153); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(154); Get();}
Expect(8);
if (isYield) {
yieldReq.Add(new MaybeFreeExpression(e, isFree));
@@ -1325,7 +1327,7 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
Attribute(ref ensAttrs);
}
Expression(out e, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(154); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(155); Get();}
Expect(8);
if (isYield) {
yieldEns.Add(new MaybeFreeExpression(e, isFree, ensAttrs));
@@ -1333,16 +1335,16 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
ens.Add(new MaybeFreeExpression(e, isFree, ensAttrs));
}
- } else SynErr(155);
+ } else SynErr(156);
} else if (la.kind == 49) {
Get();
while (IsAttribute()) {
Attribute(ref decrAttrs);
}
DecreasesList(decreases, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(156); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(157); Get();}
Expect(8);
- } else SynErr(157);
+ } else SynErr(158);
}
void BlockStmt(out BlockStmt/*!*/ block, out IToken bodyStart, out IToken bodyEnd) {
@@ -1351,7 +1353,7 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
Expect(9);
bodyStart = t;
- while (StartOf(14)) {
+ while (StartOf(15)) {
Stmt(body);
}
Expect(10);
@@ -1364,13 +1366,13 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Contract.Requires(cce.NonNullElements(req)); Contract.Requires(cce.NonNullElements(mod)); Contract.Requires(cce.NonNullElements(ens)); Contract.Requires(cce.NonNullElements(decreases));
Expression/*!*/ e; FrameExpression/*!*/ fe; bool isFree = false; Attributes ensAttrs = null;
- while (!(StartOf(15))) {SynErr(158); Get();}
+ while (!(StartOf(16))) {SynErr(159); Get();}
if (la.kind == 45) {
Get();
while (IsAttribute()) {
Attribute(ref modAttrs);
}
- if (StartOf(12)) {
+ if (StartOf(13)) {
FrameExpression(out fe);
mod.Add(fe);
while (la.kind == 31) {
@@ -1379,7 +1381,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
mod.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(159); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(160); Get();}
Expect(8);
} else if (la.kind == 46 || la.kind == 47 || la.kind == 48) {
if (la.kind == 46) {
@@ -1389,7 +1391,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 47) {
Get();
Expression(out e, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(160); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(161); Get();}
Expect(8);
req.Add(new MaybeFreeExpression(e, isFree));
} else if (la.kind == 48) {
@@ -1398,19 +1400,19 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Attribute(ref ensAttrs);
}
Expression(out e, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(161); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(162); Get();}
Expect(8);
ens.Add(new MaybeFreeExpression(e, isFree, ensAttrs));
- } else SynErr(162);
+ } else SynErr(163);
} else if (la.kind == 49) {
Get();
while (IsAttribute()) {
Attribute(ref decAttrs);
}
DecreasesList(decreases, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(163); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(164); Get();}
Expect(8);
- } else SynErr(164);
+ } else SynErr(165);
}
void FrameExpression(out FrameExpression/*!*/ fe) {
@@ -1420,7 +1422,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
string fieldName = null; IToken feTok = null;
fe = null;
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expression(out e, false);
feTok = e.tok;
if (la.kind == 65) {
@@ -1434,7 +1436,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Ident(out id);
fieldName = id.val;
fe = new FrameExpression(id, new ImplicitThisExpr(id), fieldName);
- } else SynErr(165);
+ } else SynErr(166);
}
void Expression(out Expression e, bool allowSemi) {
@@ -1516,7 +1518,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
GenericInstantiation(gt);
}
ty = new UserDefinedType(tok, tok.val, gt, path);
- } else SynErr(166);
+ } else SynErr(167);
}
void FunctionSpec(List<Expression/*!*/>/*!*/ reqs, List<FrameExpression/*!*/>/*!*/ reads, List<Expression/*!*/>/*!*/ ens, List<Expression/*!*/> decreases) {
@@ -1525,15 +1527,15 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Contract.Requires(decreases == null || cce.NonNullElements(decreases));
Expression/*!*/ e; FrameExpression/*!*/ fe;
if (la.kind == 47) {
- while (!(la.kind == 0 || la.kind == 47)) {SynErr(167); Get();}
+ while (!(la.kind == 0 || la.kind == 47)) {SynErr(168); Get();}
Get();
Expression(out e, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(168); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(169); Get();}
Expect(8);
reqs.Add(e);
} else if (la.kind == 50) {
Get();
- if (StartOf(17)) {
+ if (StartOf(18)) {
PossiblyWildFrameExpression(out fe);
reads.Add(fe);
while (la.kind == 31) {
@@ -1542,12 +1544,12 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
reads.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(169); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(170); Get();}
Expect(8);
} else if (la.kind == 48) {
Get();
Expression(out e, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(170); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(171); Get();}
Expect(8);
ens.Add(e);
} else if (la.kind == 49) {
@@ -1558,9 +1560,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
DecreasesList(decreases, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(171); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(172); Get();}
Expect(8);
- } else SynErr(172);
+ } else SynErr(173);
}
void FunctionBody(out Expression/*!*/ e, out IToken bodyStart, out IToken bodyEnd) {
@@ -1577,9 +1579,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 13) {
Get();
fe = new FrameExpression(t, new WildcardExpr(t), null);
- } else if (StartOf(12)) {
+ } else if (StartOf(13)) {
FrameExpression(out fe);
- } else SynErr(173);
+ } else SynErr(174);
}
void PossiblyWildExpression(out Expression/*!*/ e) {
@@ -1588,9 +1590,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 13) {
Get();
e = new WildcardExpr(t);
- } else if (StartOf(16)) {
+ } else if (StartOf(17)) {
Expression(out e, false);
- } else SynErr(174);
+ } else SynErr(175);
}
void Stmt(List<Statement/*!*/>/*!*/ ss) {
@@ -1607,7 +1609,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IToken bodyStart, bodyEnd;
int breakCount;
- while (!(StartOf(18))) {SynErr(175); Get();}
+ while (!(StartOf(19))) {SynErr(176); Get();}
switch (la.kind) {
case 9: {
BlockStmt(out bs, out bodyStart, out bodyEnd);
@@ -1678,8 +1680,8 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
breakCount++;
}
- } else SynErr(176);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(177); Get();}
+ } else SynErr(177);
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(178); Get();}
Expect(8);
s = label != null ? new BreakStmt(x, t, label) : new BreakStmt(x, t, breakCount);
break;
@@ -1692,7 +1694,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
SkeletonStmt(out s);
break;
}
- default: SynErr(178); break;
+ default: SynErr(179); break;
}
}
@@ -1706,12 +1708,12 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
while (IsAttribute()) {
Attribute(ref attrs);
}
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expression(out e, false);
} else if (la.kind == 37) {
Get();
dotdotdot = t;
- } else SynErr(179);
+ } else SynErr(180);
Expect(8);
if (dotdotdot != null) {
s = new SkeletonStatement(new AssertStmt(x, t, new LiteralExpr(x, true), attrs), dotdotdot, null);
@@ -1731,12 +1733,12 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
while (IsAttribute()) {
Attribute(ref attrs);
}
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expression(out e, false);
} else if (la.kind == 37) {
Get();
dotdotdot = t;
- } else SynErr(180);
+ } else SynErr(181);
Expect(8);
if (dotdotdot != null) {
s = new SkeletonStatement(new AssumeStmt(x, t, new LiteralExpr(x, true), attrs), dotdotdot, null);
@@ -1806,13 +1808,13 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
suchThatAssume = t;
}
Expression(out suchThat, false);
- } else SynErr(181);
+ } else SynErr(182);
Expect(8);
endTok = t;
} else if (la.kind == 7) {
Get();
SemErr(t, "invalid statement (did you forget the 'label' keyword?)");
- } else SynErr(182);
+ } else SynErr(183);
if (suchThat != null) {
s = new AssignSuchThatStmt(x, endTok, lhss, suchThat, suchThatAssume);
} else {
@@ -1916,8 +1918,8 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (IsAlternative()) {
AlternativeBlock(out alternatives, out endTok);
ifStmt = new AlternativeStmt(x, endTok, alternatives);
- } else if (StartOf(19)) {
- if (StartOf(20)) {
+ } else if (StartOf(20)) {
+ if (StartOf(21)) {
Guard(out guard);
} else {
Get();
@@ -1933,7 +1935,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 9) {
BlockStmt(out bs, out bodyStart, out bodyEnd);
els = bs; endTok = bs.EndTok;
- } else SynErr(183);
+ } else SynErr(184);
}
if (guardEllipsis != null) {
ifStmt = new SkeletonStatement(new IfStmt(x, endTok, guard, thn, els), guardEllipsis, null);
@@ -1941,7 +1943,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
ifStmt = new IfStmt(x, endTok, guard, thn, els);
}
- } else SynErr(184);
+ } else SynErr(185);
}
void WhileStmt(out Statement/*!*/ stmt) {
@@ -1963,8 +1965,8 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
LoopSpec(out invariants, out decreases, out mod, ref decAttrs, ref modAttrs);
AlternativeBlock(out alternatives, out endTok);
stmt = new AlternativeLoopStmt(x, endTok, invariants, new Specification<Expression>(decreases, decAttrs), new Specification<FrameExpression>(mod, modAttrs), alternatives);
- } else if (StartOf(19)) {
- if (StartOf(20)) {
+ } else if (StartOf(20)) {
+ if (StartOf(21)) {
Guard(out guard);
Contract.Assume(guard == null || cce.Owner.None(guard));
} else {
@@ -1978,7 +1980,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 37) {
Get();
bodyEllipsis = t; endTok = t;
- } else SynErr(185);
+ } else SynErr(186);
if (guardEllipsis != null || bodyEllipsis != null) {
if (mod != null) {
SemErr(mod[0].E.tok, "'modifies' clauses are not allowed on refining loops");
@@ -1994,7 +1996,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
stmt = new WhileStmt(x, endTok, guard, invariants, new Specification<Expression>(decreases, decAttrs), new Specification<FrameExpression>(mod, modAttrs), body);
}
- } else SynErr(186);
+ } else SynErr(187);
}
void MatchStmt(out Statement/*!*/ s) {
@@ -2016,9 +2018,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
if (CloseOptionalBrace(usesOptionalBrace)) {
Expect(10);
- } else if (StartOf(21)) {
+ } else if (StartOf(22)) {
if (usesOptionalBrace) { SemErr(t, "expecting close curly brace"); }
- } else SynErr(187);
+ } else SynErr(188);
s = new MatchStmt(x, t, e, cases, usesOptionalBrace);
}
@@ -2044,7 +2046,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
x = t;
errors.Warning(t, "the 'parallel' keyword has been deprecated; the comprehension statement now uses the keyword 'forall' (and the parentheses around the bound variables are now optional)");
- } else SynErr(188);
+ } else SynErr(189);
if (la.kind == 11) {
Get();
usesOptionalParen = true;
@@ -2060,9 +2062,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (CloseOptionalParen(usesOptionalParen)) {
Expect(12);
- } else if (StartOf(22)) {
+ } else if (StartOf(23)) {
if (usesOptionalParen) { SemErr(t, "expecting close parenthesis"); }
- } else SynErr(189);
+ } else SynErr(190);
while (la.kind == 46 || la.kind == 48) {
isFree = false;
if (la.kind == 46) {
@@ -2105,7 +2107,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expect(88);
x = t;
- if (StartOf(23)) {
+ if (StartOf(24)) {
CalcOp(out opTok, out calcOp);
maybeOp = calcOp.ResultOp(calcOp); // guard against non-transitive calcOp (like !=)
if (maybeOp == null) {
@@ -2115,11 +2117,11 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
Expect(9);
- while (StartOf(16)) {
+ while (StartOf(17)) {
Expression(out e, false);
lines.Add(e); stepOp = calcOp; danglingOperator = null;
Expect(8);
- if (StartOf(23)) {
+ if (StartOf(24)) {
CalcOp(out opTok, out op);
maybeOp = resOp.ResultOp(op);
if (maybeOp == null) {
@@ -2161,8 +2163,8 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
while (IsAttribute()) {
Attribute(ref attrs);
}
- if (StartOf(24)) {
- if (StartOf(12)) {
+ if (StartOf(25)) {
+ if (StartOf(13)) {
FrameExpression(out fe);
mod.Add(fe);
while (la.kind == 31) {
@@ -2178,10 +2180,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 9) {
BlockStmt(out body, out bodyStart, out endTok);
} else if (la.kind == 8) {
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(190); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(191); Get();}
Get();
endTok = t;
- } else SynErr(191);
+ } else SynErr(192);
s = new ModifyStmt(tok, endTok, mod, attrs, body);
if (ellipsisToken != null) {
s = new SkeletonStatement(s, ellipsisToken, null);
@@ -2201,8 +2203,8 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 51) {
Get();
returnTok = t; isYield = true;
- } else SynErr(192);
- if (StartOf(25)) {
+ } else SynErr(193);
+ if (StartOf(26)) {
Rhs(out r, null);
rhss = new List<AssignmentRhs>(); rhss.Add(r);
while (la.kind == 31) {
@@ -2283,7 +2285,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Ident(out x);
}
Expect(11);
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expressions(args);
}
Expect(12);
@@ -2300,10 +2302,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 13) {
Get();
r = new HavocRhs(t);
- } else if (StartOf(16)) {
+ } else if (StartOf(17)) {
Expression(out e, false);
r = new ExprRhs(e);
- } else SynErr(193);
+ } else SynErr(194);
while (la.kind == 9) {
Attribute(ref attrs);
}
@@ -2318,13 +2320,13 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
while (la.kind == 61 || la.kind == 74) {
Suffix(ref e);
}
- } else if (StartOf(26)) {
+ } else if (StartOf(27)) {
ConstAtomExpression(out e);
Suffix(ref e);
while (la.kind == 61 || la.kind == 74) {
Suffix(ref e);
}
- } else SynErr(194);
+ } else SynErr(195);
}
void Expressions(List<Expression/*!*/>/*!*/ args) {
@@ -2351,7 +2353,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expression(out e, true);
Expect(79);
body = new List<Statement>();
- while (StartOf(14)) {
+ while (StartOf(15)) {
Stmt(body);
}
alternatives.Add(new GuardedAlternative(x, e, body));
@@ -2370,10 +2372,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expect(13);
Expect(12);
e = null;
- } else if (StartOf(16)) {
+ } else if (StartOf(17)) {
Expression(out ee, true);
e = ee;
- } else SynErr(195);
+ } else SynErr(196);
}
void LoopSpec(out List<MaybeFreeExpression/*!*/> invariants, out List<Expression/*!*/> decreases, out List<FrameExpression/*!*/> mod, ref Attributes decAttrs, ref Attributes modAttrs) {
@@ -2383,29 +2385,29 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
decreases = new List<Expression/*!*/>();
mod = null;
- while (StartOf(27)) {
+ while (StartOf(28)) {
if (la.kind == 46 || la.kind == 81) {
Invariant(out invariant);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(196); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(197); Get();}
Expect(8);
invariants.Add(invariant);
} else if (la.kind == 49) {
- while (!(la.kind == 0 || la.kind == 49)) {SynErr(197); Get();}
+ while (!(la.kind == 0 || la.kind == 49)) {SynErr(198); Get();}
Get();
while (IsAttribute()) {
Attribute(ref decAttrs);
}
DecreasesList(decreases, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(198); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(199); Get();}
Expect(8);
} else {
- while (!(la.kind == 0 || la.kind == 45)) {SynErr(199); Get();}
+ while (!(la.kind == 0 || la.kind == 45)) {SynErr(200); Get();}
Get();
while (IsAttribute()) {
Attribute(ref modAttrs);
}
mod = mod ?? new List<FrameExpression>();
- if (StartOf(12)) {
+ if (StartOf(13)) {
FrameExpression(out fe);
mod.Add(fe);
while (la.kind == 31) {
@@ -2414,7 +2416,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
mod.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(200); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(201); Get();}
Expect(8);
}
}
@@ -2422,7 +2424,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
void Invariant(out MaybeFreeExpression/*!*/ invariant) {
bool isFree = false; Expression/*!*/ e; List<string> ids = new List<string>(); invariant = null; Attributes attrs = null;
- while (!(la.kind == 0 || la.kind == 46 || la.kind == 81)) {SynErr(201); Get();}
+ while (!(la.kind == 0 || la.kind == 46 || la.kind == 81)) {SynErr(202); Get();}
if (la.kind == 46) {
Get();
isFree = true;
@@ -2457,7 +2459,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expect(12);
}
Expect(79);
- while (StartOf(14)) {
+ while (StartOf(15)) {
Stmt(body);
}
c = new MatchCaseStmt(x, id.val, arguments, body);
@@ -2468,10 +2470,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 6) {
Get();
arg = new Attributes.Argument(t, t.val.Substring(1, t.val.Length-2));
- } else if (StartOf(16)) {
+ } else if (StartOf(17)) {
Expression(out e, allowSemi);
arg = new Attributes.Argument(t, e);
- } else SynErr(202);
+ } else SynErr(203);
}
void QuantifierDomain(out List<BoundVar> bvars, out Attributes attrs, out Expression range) {
@@ -2568,7 +2570,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
x = t; binOp = BinaryExpr.Opcode.Exp;
break;
}
- default: SynErr(203); break;
+ default: SynErr(204); break;
}
if (k == null) {
op = new Microsoft.Dafny.CalcStmt.BinaryCalcOp(binOp);
@@ -2605,7 +2607,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 97) {
Get();
- } else SynErr(204);
+ } else SynErr(205);
}
void ImpliesOp() {
@@ -2613,7 +2615,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 99) {
Get();
- } else SynErr(205);
+ } else SynErr(206);
}
void ExpliesOp() {
@@ -2621,7 +2623,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 101) {
Get();
- } else SynErr(206);
+ } else SynErr(207);
}
void EquivExpression(out Expression e0, bool allowSemi) {
@@ -2638,7 +2640,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
void ImpliesExpliesExpression(out Expression e0, bool allowSemi) {
Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expression/*!*/ e1;
LogicalExpression(out e0, allowSemi);
- if (StartOf(28)) {
+ if (StartOf(29)) {
if (la.kind == 98 || la.kind == 99) {
ImpliesOp();
x = t;
@@ -2662,7 +2664,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
void LogicalExpression(out Expression e0, bool allowSemi) {
Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expression/*!*/ e1;
RelationalExpression(out e0, allowSemi);
- if (StartOf(29)) {
+ if (StartOf(30)) {
if (la.kind == 102 || la.kind == 103) {
AndOp();
x = t;
@@ -2716,7 +2718,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Term(out e0, allowSemi);
e = e0;
- if (StartOf(30)) {
+ if (StartOf(31)) {
RelOp(out x, out op, out k);
firstOpTok = x;
Term(out e1, allowSemi);
@@ -2729,7 +2731,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = new TernaryExpr(x, op == BinaryExpr.Opcode.Eq ? TernaryExpr.Opcode.PrefixEqOp : TernaryExpr.Opcode.PrefixNeqOp, k, e0, e1);
}
- while (StartOf(30)) {
+ while (StartOf(31)) {
if (chain == null) {
chain = new List<Expression>();
ops = new List<BinaryExpr.Opcode>();
@@ -2806,7 +2808,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 103) {
Get();
- } else SynErr(207);
+ } else SynErr(208);
}
void OrOp() {
@@ -2814,7 +2816,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 105) {
Get();
- } else SynErr(208);
+ } else SynErr(209);
}
void Term(out Expression e0, bool allowSemi) {
@@ -2919,7 +2921,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
x = t; op = BinaryExpr.Opcode.Ge;
break;
}
- default: SynErr(209); break;
+ default: SynErr(210); break;
}
}
@@ -2941,7 +2943,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 109) {
Get();
x = t; op = BinaryExpr.Opcode.Sub;
- } else SynErr(210);
+ } else SynErr(211);
}
void UnaryExpression(out Expression e, bool allowSemi) {
@@ -2996,9 +2998,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
} else if (la.kind == 1) {
MapComprehensionExpr(x, out e, allowSemi);
- } else if (StartOf(31)) {
+ } else if (StartOf(32)) {
SemErr("map must be followed by literal in brackets or comprehension.");
- } else SynErr(211);
+ } else SynErr(212);
break;
}
case 2: case 3: case 4: case 11: case 29: case 54: case 55: case 113: case 114: case 115: case 116: case 117: case 118: {
@@ -3008,7 +3010,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
break;
}
- default: SynErr(212); break;
+ default: SynErr(213); break;
}
}
@@ -3023,7 +3025,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 111) {
Get();
x = t; op = BinaryExpr.Opcode.Mod;
- } else SynErr(213);
+ } else SynErr(214);
}
void NegOp() {
@@ -3031,7 +3033,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 112) {
Get();
- } else SynErr(214);
+ } else SynErr(215);
}
void EndlessExpression(out Expression e, bool allowSemi) {
@@ -3078,7 +3080,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
NamedExpr(out e, allowSemi);
break;
}
- default: SynErr(215); break;
+ default: SynErr(216); break;
}
}
@@ -3107,7 +3109,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
Expect(11);
openParen = t;
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expressions(args);
}
Expect(12);
@@ -3141,7 +3143,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
Expect(11);
IToken openParen = t;
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expressions(args);
}
Expect(12);
@@ -3151,13 +3153,13 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 74) {
Get();
x = t;
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expression(out ee, true);
e0 = ee;
if (la.kind == 120) {
Get();
anyDots = true;
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expression(out ee, true);
e1 = ee;
}
@@ -3174,7 +3176,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
takeRest = true;
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expression(out ee, true);
multipleLengths.Add(ee);
takeRest = false;
@@ -3192,15 +3194,15 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
multipleIndices.Add(ee);
}
- } else SynErr(216);
+ } else SynErr(217);
} else if (la.kind == 120) {
Get();
anyDots = true;
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expression(out ee, true);
e1 = ee;
}
- } else SynErr(217);
+ } else SynErr(218);
if (multipleIndices != null) {
e = new MultiSelectExpr(x, e, multipleIndices);
// make sure an array class with this dimensionality exists
@@ -3241,7 +3243,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
Expect(75);
- } else SynErr(218);
+ } else SynErr(219);
}
void DisplayExpr(out Expression e) {
@@ -3252,7 +3254,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 9) {
Get();
x = t; elements = new List<Expression/*!*/>();
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expressions(elements);
}
e = new SetDisplayExpr(x, elements);
@@ -3260,12 +3262,12 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 74) {
Get();
x = t; elements = new List<Expression/*!*/>();
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expressions(elements);
}
e = new SeqDisplayExpr(x, elements);
Expect(75);
- } else SynErr(219);
+ } else SynErr(220);
}
void MultiSetExpr(out Expression e) {
@@ -3278,7 +3280,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 9) {
Get();
elements = new List<Expression/*!*/>();
- if (StartOf(16)) {
+ if (StartOf(17)) {
Expressions(elements);
}
e = new MultiSetDisplayExpr(x, elements);
@@ -3289,9 +3291,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expression(out e, true);
e = new MultiSetFormingExpr(x, e);
Expect(12);
- } else if (StartOf(32)) {
+ } else if (StartOf(33)) {
SemErr("multiset must be followed by multiset literal or expression to coerce in parentheses.");
- } else SynErr(220);
+ } else SynErr(221);
}
void MapDisplayExpr(IToken/*!*/ mapToken, out Expression e) {
@@ -3300,7 +3302,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = dummyExpr;
Expect(74);
- if (StartOf(16)) {
+ if (StartOf(17)) {
MapLiteralExpressions(out elements);
}
e = new MapDisplayExpr(mapToken, elements);
@@ -3406,7 +3408,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
ParensExpression(out e);
break;
}
- default: SynErr(221); break;
+ default: SynErr(222); break;
}
}
@@ -3431,7 +3433,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
n = BigInteger.Zero;
}
- } else SynErr(222);
+ } else SynErr(223);
}
void Dec(out Basetypes.BigDec d) {
@@ -3457,7 +3459,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
var tmp = theBuiltIns.TupleType(x, 0, true);
e = new DatatypeValue(x, BuiltIns.TupleTypeName(0), BuiltIns.TupleTypeCtorName, new List<Expression>());
- } else if (StartOf(16)) {
+ } else if (StartOf(17)) {
Expression(out e, true);
while (la.kind == 31) {
Get();
@@ -3478,7 +3480,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = new DatatypeValue(x, BuiltIns.TupleTypeName(args.Count), BuiltIns.TupleTypeCtorName, args);
}
- } else SynErr(223);
+ } else SynErr(224);
}
void MapLiteralExpressions(out List<ExpressionPair> elements) {
@@ -3502,7 +3504,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 125) {
Get();
- } else SynErr(224);
+ } else SynErr(225);
}
void MatchExpression(out Expression e, bool allowSemi) {
@@ -3523,9 +3525,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
if (CloseOptionalBrace(usesOptionalBrace)) {
Expect(10);
- } else if (StartOf(31)) {
+ } else if (StartOf(32)) {
if (usesOptionalBrace) { SemErr(t, "expecting close curly brace"); }
- } else SynErr(225);
+ } else SynErr(226);
e = new MatchExpr(x, e, cases, usesOptionalBrace);
}
@@ -3543,7 +3545,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 122 || la.kind == 123) {
Exists();
x = t;
- } else SynErr(226);
+ } else SynErr(227);
QuantifierDomain(out bvars, out attrs, out range);
QSep();
Expression(out body, allowSemi);
@@ -3591,7 +3593,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
AssumeStmt(out s);
} else if (la.kind == 88) {
CalcStmt(out s);
- } else SynErr(227);
+ } else SynErr(228);
}
void LetExpr(out Expression e, bool allowSemi) {
@@ -3631,7 +3633,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
}
- } else SynErr(228);
+ } else SynErr(229);
Expression(out e, false);
letRHSs.Add(e);
while (la.kind == 31) {
@@ -3682,7 +3684,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IdentTypeOptional(out bv);
pat = new CasePattern(bv.tok, bv);
- } else SynErr(229);
+ } else SynErr(230);
}
void CaseExpression(out MatchCaseExpr c, bool allowSemi) {
@@ -3715,7 +3717,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 121) {
Get();
- } else SynErr(230);
+ } else SynErr(231);
}
void Exists() {
@@ -3723,7 +3725,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Get();
} else if (la.kind == 123) {
Get();
- } else SynErr(231);
+ } else SynErr(232);
}
void AttributeBody(ref Attributes attrs) {
@@ -3734,7 +3736,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expect(7);
Expect(1);
aName = t.val;
- if (StartOf(33)) {
+ if (StartOf(34)) {
AttributeArg(out aArg, true);
aArgs.Add(aArg);
while (la.kind == 31) {
@@ -3762,6 +3764,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
{T,T,T,T, T,x,x,x, T,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,T, T,T,T,x, x,x,T,x, x,T,x,x, T,T,T,T, T,T,T,T, T,T,T,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, T,x,x,x, T,x,x,x, T,T,T,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,T, x,x,x,x, T,T,T,T, T,x,T,x, T,x,T,x, x,x,x,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,T,x, x,x,x,x, x,x,x,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x},
+ {T,x,x,x, x,x,x,x, T,x,T,x, x,x,x,x, T,T,x,T, x,T,x,x, T,T,T,T, T,x,T,x, T,x,T,x, x,x,T,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x},
{x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x},
{T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, T,T,x,T, x,x,x,x, T,T,T,T, T,x,T,x, T,x,T,x, x,x,T,x, T,T,T,T, T,x,x,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x},
@@ -3950,105 +3953,106 @@ public class Errors {
case 130: s = "this symbol not expected in DatatypeDecl"; break;
case 131: s = "invalid DatatypeDecl"; break;
case 132: s = "this symbol not expected in DatatypeDecl"; break;
- case 133: s = "this symbol not expected in OtherTypeDecl"; break;
- case 134: s = "this symbol not expected in IteratorDecl"; break;
- case 135: s = "invalid IteratorDecl"; break;
- case 136: s = "invalid ClassMemberDecl"; break;
- case 137: s = "invalid IdentOrDigitsSuffix"; break;
- case 138: s = "this symbol not expected in FieldDecl"; break;
+ case 133: s = "invalid OtherTypeDecl"; break;
+ case 134: s = "this symbol not expected in OtherTypeDecl"; break;
+ case 135: s = "this symbol not expected in IteratorDecl"; break;
+ case 136: s = "invalid IteratorDecl"; break;
+ case 137: s = "invalid ClassMemberDecl"; break;
+ case 138: s = "invalid IdentOrDigitsSuffix"; break;
case 139: s = "this symbol not expected in FieldDecl"; break;
- case 140: s = "invalid FunctionDecl"; break;
+ case 140: s = "this symbol not expected in FieldDecl"; break;
case 141: s = "invalid FunctionDecl"; break;
case 142: s = "invalid FunctionDecl"; break;
case 143: s = "invalid FunctionDecl"; break;
- case 144: s = "this symbol not expected in MethodDecl"; break;
- case 145: s = "invalid MethodDecl"; break;
+ case 144: s = "invalid FunctionDecl"; break;
+ case 145: s = "this symbol not expected in MethodDecl"; break;
case 146: s = "invalid MethodDecl"; break;
- case 147: s = "invalid FIdentType"; break;
- case 148: s = "invalid TypeIdentOptional"; break;
- case 149: s = "invalid TypeAndToken"; break;
- case 150: s = "this symbol not expected in IteratorSpec"; break;
+ case 147: s = "invalid MethodDecl"; break;
+ case 148: s = "invalid FIdentType"; break;
+ case 149: s = "invalid TypeIdentOptional"; break;
+ case 150: s = "invalid TypeAndToken"; break;
case 151: s = "this symbol not expected in IteratorSpec"; break;
case 152: s = "this symbol not expected in IteratorSpec"; break;
case 153: s = "this symbol not expected in IteratorSpec"; break;
case 154: s = "this symbol not expected in IteratorSpec"; break;
- case 155: s = "invalid IteratorSpec"; break;
- case 156: s = "this symbol not expected in IteratorSpec"; break;
- case 157: s = "invalid IteratorSpec"; break;
- case 158: s = "this symbol not expected in MethodSpec"; break;
+ case 155: s = "this symbol not expected in IteratorSpec"; break;
+ case 156: s = "invalid IteratorSpec"; break;
+ case 157: s = "this symbol not expected in IteratorSpec"; break;
+ case 158: s = "invalid IteratorSpec"; break;
case 159: s = "this symbol not expected in MethodSpec"; break;
case 160: s = "this symbol not expected in MethodSpec"; break;
case 161: s = "this symbol not expected in MethodSpec"; break;
- case 162: s = "invalid MethodSpec"; break;
- case 163: s = "this symbol not expected in MethodSpec"; break;
- case 164: s = "invalid MethodSpec"; break;
- case 165: s = "invalid FrameExpression"; break;
- case 166: s = "invalid ReferenceType"; break;
- case 167: s = "this symbol not expected in FunctionSpec"; break;
+ case 162: s = "this symbol not expected in MethodSpec"; break;
+ case 163: s = "invalid MethodSpec"; break;
+ case 164: s = "this symbol not expected in MethodSpec"; break;
+ case 165: s = "invalid MethodSpec"; break;
+ case 166: s = "invalid FrameExpression"; break;
+ case 167: s = "invalid ReferenceType"; break;
case 168: s = "this symbol not expected in FunctionSpec"; break;
case 169: s = "this symbol not expected in FunctionSpec"; break;
case 170: s = "this symbol not expected in FunctionSpec"; break;
case 171: s = "this symbol not expected in FunctionSpec"; break;
- case 172: s = "invalid FunctionSpec"; break;
- case 173: s = "invalid PossiblyWildFrameExpression"; break;
- case 174: s = "invalid PossiblyWildExpression"; break;
- case 175: s = "this symbol not expected in OneStmt"; break;
- case 176: s = "invalid OneStmt"; break;
- case 177: s = "this symbol not expected in OneStmt"; break;
- case 178: s = "invalid OneStmt"; break;
- case 179: s = "invalid AssertStmt"; break;
- case 180: s = "invalid AssumeStmt"; break;
- case 181: s = "invalid UpdateStmt"; break;
+ case 172: s = "this symbol not expected in FunctionSpec"; break;
+ case 173: s = "invalid FunctionSpec"; break;
+ case 174: s = "invalid PossiblyWildFrameExpression"; break;
+ case 175: s = "invalid PossiblyWildExpression"; break;
+ case 176: s = "this symbol not expected in OneStmt"; break;
+ case 177: s = "invalid OneStmt"; break;
+ case 178: s = "this symbol not expected in OneStmt"; break;
+ case 179: s = "invalid OneStmt"; break;
+ case 180: s = "invalid AssertStmt"; break;
+ case 181: s = "invalid AssumeStmt"; break;
case 182: s = "invalid UpdateStmt"; break;
- case 183: s = "invalid IfStmt"; break;
+ case 183: s = "invalid UpdateStmt"; break;
case 184: s = "invalid IfStmt"; break;
- case 185: s = "invalid WhileStmt"; break;
+ case 185: s = "invalid IfStmt"; break;
case 186: s = "invalid WhileStmt"; break;
- case 187: s = "invalid MatchStmt"; break;
- case 188: s = "invalid ForallStmt"; break;
+ case 187: s = "invalid WhileStmt"; break;
+ case 188: s = "invalid MatchStmt"; break;
case 189: s = "invalid ForallStmt"; break;
- case 190: s = "this symbol not expected in ModifyStmt"; break;
- case 191: s = "invalid ModifyStmt"; break;
- case 192: s = "invalid ReturnStmt"; break;
- case 193: s = "invalid Rhs"; break;
- case 194: s = "invalid Lhs"; break;
- case 195: s = "invalid Guard"; break;
- case 196: s = "this symbol not expected in LoopSpec"; break;
+ case 190: s = "invalid ForallStmt"; break;
+ case 191: s = "this symbol not expected in ModifyStmt"; break;
+ case 192: s = "invalid ModifyStmt"; break;
+ case 193: s = "invalid ReturnStmt"; break;
+ case 194: s = "invalid Rhs"; break;
+ case 195: s = "invalid Lhs"; break;
+ case 196: s = "invalid Guard"; break;
case 197: s = "this symbol not expected in LoopSpec"; break;
case 198: s = "this symbol not expected in LoopSpec"; break;
case 199: s = "this symbol not expected in LoopSpec"; break;
case 200: s = "this symbol not expected in LoopSpec"; break;
- case 201: s = "this symbol not expected in Invariant"; break;
- case 202: s = "invalid AttributeArg"; break;
- case 203: s = "invalid CalcOp"; break;
- case 204: s = "invalid EquivOp"; break;
- case 205: s = "invalid ImpliesOp"; break;
- case 206: s = "invalid ExpliesOp"; break;
- case 207: s = "invalid AndOp"; break;
- case 208: s = "invalid OrOp"; break;
- case 209: s = "invalid RelOp"; break;
- case 210: s = "invalid AddOp"; break;
- case 211: s = "invalid UnaryExpression"; break;
+ case 201: s = "this symbol not expected in LoopSpec"; break;
+ case 202: s = "this symbol not expected in Invariant"; break;
+ case 203: s = "invalid AttributeArg"; break;
+ case 204: s = "invalid CalcOp"; break;
+ case 205: s = "invalid EquivOp"; break;
+ case 206: s = "invalid ImpliesOp"; break;
+ case 207: s = "invalid ExpliesOp"; break;
+ case 208: s = "invalid AndOp"; break;
+ case 209: s = "invalid OrOp"; break;
+ case 210: s = "invalid RelOp"; break;
+ case 211: s = "invalid AddOp"; break;
case 212: s = "invalid UnaryExpression"; break;
- case 213: s = "invalid MulOp"; break;
- case 214: s = "invalid NegOp"; break;
- case 215: s = "invalid EndlessExpression"; break;
- case 216: s = "invalid Suffix"; break;
+ case 213: s = "invalid UnaryExpression"; break;
+ case 214: s = "invalid MulOp"; break;
+ case 215: s = "invalid NegOp"; break;
+ case 216: s = "invalid EndlessExpression"; break;
case 217: s = "invalid Suffix"; break;
case 218: s = "invalid Suffix"; break;
- case 219: s = "invalid DisplayExpr"; break;
- case 220: s = "invalid MultiSetExpr"; break;
- case 221: s = "invalid ConstAtomExpression"; break;
- case 222: s = "invalid Nat"; break;
- case 223: s = "invalid ParensExpression"; break;
- case 224: s = "invalid QSep"; break;
- case 225: s = "invalid MatchExpression"; break;
- case 226: s = "invalid QuantifierGuts"; break;
- case 227: s = "invalid StmtInExpr"; break;
- case 228: s = "invalid LetExpr"; break;
- case 229: s = "invalid CasePattern"; break;
- case 230: s = "invalid Forall"; break;
- case 231: s = "invalid Exists"; break;
+ case 219: s = "invalid Suffix"; break;
+ case 220: s = "invalid DisplayExpr"; break;
+ case 221: s = "invalid MultiSetExpr"; break;
+ case 222: s = "invalid ConstAtomExpression"; break;
+ case 223: s = "invalid Nat"; break;
+ case 224: s = "invalid ParensExpression"; break;
+ case 225: s = "invalid QSep"; break;
+ case 226: s = "invalid MatchExpression"; break;
+ case 227: s = "invalid QuantifierGuts"; break;
+ case 228: s = "invalid StmtInExpr"; break;
+ case 229: s = "invalid LetExpr"; break;
+ case 230: s = "invalid CasePattern"; break;
+ case 231: s = "invalid Forall"; break;
+ case 232: s = "invalid Exists"; break;
default: s = "error " + n; break;
}
diff --git a/Source/Dafny/RefinementTransformer.cs b/Source/Dafny/RefinementTransformer.cs
index 5ddcef55..8fbb9d9b 100644
--- a/Source/Dafny/RefinementTransformer.cs
+++ b/Source/Dafny/RefinementTransformer.cs
@@ -154,31 +154,34 @@ namespace Microsoft.Dafny
if (dDemandsEqualitySupport != ((ArbitraryTypeDecl)nw).MustSupportEquality) {
reporter.Error(nw, "type declaration '{0}' is not allowed to change the requirement of supporting equality", nw.Name);
}
+ if (nw.TypeArgs.Count != d.TypeArgs.Count) {
+ reporter.Error(nw, "type '{0}' is not allowed to change its number of type parameters (got {1}, expected {2})", nw.Name, nw.TypeArgs.Count, d.TypeArgs.Count);
+ }
} else if (dDemandsEqualitySupport) {
if (nw is ClassDecl) {
// fine, as long as "nw" does not take any type parameters
if (nw.TypeArgs.Count != d.TypeArgs.Count) {
- reporter.Error(nw, "arbitrary type '{0}' is not allowed to be replaced by a class that takes a different number of type parameters", nw.Name);
+ reporter.Error(nw, "arbitrary type '{0}' is not allowed to be replaced by a class that takes a different number of type parameters (got {1}, expected {2})", nw.Name, nw.TypeArgs.Count, d.TypeArgs.Count);
}
} else if (nw is CoDatatypeDecl) {
reporter.Error(nw, "a type declaration that requires equality support cannot be replaced by a codatatype");
} else {
- Contract.Assert(nw is IndDatatypeDecl);
+ Contract.Assert(nw is IndDatatypeDecl || nw is TypeSynonymDecl);
if (nw.TypeArgs.Count != d.TypeArgs.Count) {
- reporter.Error(nw, "arbitrary type '{0}' is not allowed to be replaced by a datatype that takes a different number of type parameters", nw.Name);
+ reporter.Error(nw, "arbitrary type '{0}' is not allowed to be replaced by a type that takes a different number of type parameters (got {1}, expected {2})", nw.Name, nw.TypeArgs.Count, d.TypeArgs.Count);
} else {
// Here, we need to figure out if the new type supports equality. But we won't know about that until resolution has
// taken place, so we defer it until the PostResolve phase.
- var udt = new UserDefinedType(nw.tok, nw.Name, nw, new List<Type>());
- postTasks.Enqueue(delegate() {
+ var udt = new UserDefinedType(nw.tok, nw.Name, nw, nw.TypeArgs.ConvertAll(tp => (Type)new UserDefinedType(tp)));
+ postTasks.Enqueue(() => {
if (!udt.SupportsEquality) {
- reporter.Error(udt.tok, "datatype '{0}' is used to refine an arbitrary type with equality support, but '{0}' does not support equality", udt.Name);
+ reporter.Error(udt.tok, "type '{0}' is used to refine an arbitrary type with equality support, but '{0}' does not support equality", udt.Name);
}
});
}
}
} else if (d.TypeArgs.Count != nw.TypeArgs.Count) {
- reporter.Error(nw, "arbitrary type '{0}' is not allowed to be replaced by a type that takes a different number of type parameters", nw.Name);
+ reporter.Error(nw, "arbitrary type '{0}' is not allowed to be replaced by a type that takes a different number of type parameters (got {1}, expected {2})", nw.Name, nw.TypeArgs.Count, d.TypeArgs.Count);
}
}
} else if (nw is ArbitraryTypeDecl) {
diff --git a/Source/Dafny/Resolver.cs b/Source/Dafny/Resolver.cs
index 551ab335..e681ce51 100644
--- a/Source/Dafny/Resolver.cs
+++ b/Source/Dafny/Resolver.cs
@@ -1041,7 +1041,7 @@ namespace Microsoft.Dafny
if (d is ArbitraryTypeDecl) {
var dd = (ArbitraryTypeDecl)d;
- return new ArbitraryTypeDecl(dd.tok, dd.Name, m, dd.EqualitySupport, null);
+ return new ArbitraryTypeDecl(dd.tok, dd.Name, m, dd.EqualitySupport, dd.TypeArgs.ConvertAll(CloneTypeParam), null);
} else if (d is TypeSynonymDecl) {
var dd = (TypeSynonymDecl)d;
var tps = dd.TypeArgs.ConvertAll(CloneTypeParam);
@@ -7238,7 +7238,7 @@ namespace Microsoft.Dafny
CallRhs ResolveIdentifierSequenceModuleScope(IdentifierSequence e, int p, ModuleSignature sig, bool twoState, ICodeContext codeContext, bool allowMethodCall) {
// Look up "id" as follows:
- // - unamibugous type/module name (class, datatype, sub-module (including submodules of imports) or arbitrary-type)
+ // - unambiguous type/module name (class, datatype, sub-module (including submodules of imports) or arbitrary-type)
// (if two imported types have the same name, an error message is produced here)
// - static function or method of sig.
// This is used to look up names that appear after a dot in a sequence identifier. For example, in X.M.*, M should be looked up in X, but
@@ -7255,17 +7255,19 @@ namespace Microsoft.Dafny
if (sig.TopLevels.TryGetValue(id.val, out decl)) {
if (decl is AmbiguousTopLevelDecl) {
Error(id, "The name {0} ambiguously refers to a something in one of the modules {1}", id.val, ((AmbiguousTopLevelDecl)decl).ModuleNames());
- } else if (decl is ClassDecl) {
- // ----- root is a class
- var cd = (ClassDecl)decl;
- r = ResolveSuffix(new StaticReceiverExpr(id, cd), e, p + 1, twoState, codeContext, allowMethodCall, out call);
-
} else if (decl is ModuleDecl) {
// ----- root is a submodule
if (!(p + 1 < e.Tokens.Count)) {
Error(e.tok, "module {0} cannot be used here", ((ModuleDecl)decl).Name);
}
call = ResolveIdentifierSequenceModuleScope(e, p + 1, ((ModuleDecl)decl).Signature, twoState, codeContext, allowMethodCall);
+ } else if (decl is TypeSynonymDecl) {
+ // ----- root apparently refers to a type synonym
+ Error(e.tok, "type synonym {0} cannot be used here", id.val); // todo: this is a bit of a cop-out; perhaps something better could be done
+ } else if (decl is ClassDecl) {
+ // ----- root is a class
+ var cd = (ClassDecl)decl;
+ r = ResolveSuffix(new StaticReceiverExpr(id, cd), e, p + 1, twoState, codeContext, allowMethodCall, out call);
} else {
// ----- root is a datatype
var dt = (DatatypeDecl)decl; // otherwise, unexpected TopLevelDecl
diff --git a/Source/Dafny/Translator.cs b/Source/Dafny/Translator.cs
index 3a5f8ded..e5812955 100644
--- a/Source/Dafny/Translator.cs
+++ b/Source/Dafny/Translator.cs
@@ -7012,15 +7012,15 @@ namespace Microsoft.Dafny {
}
int N = Math.Min(contextDecreases.Count, calleeDecreases.Count);
- List<IToken> toks = new List<IToken>();
- List<Type> types0 = new List<Type>();
- List<Type> types1 = new List<Type>();
- List<Expr> callee = new List<Expr>();
- List<Expr> caller = new List<Expr>();
+ var toks = new List<IToken>();
+ var types0 = new List<Type>();
+ var types1 = new List<Type>();
+ var callee = new List<Expr>();
+ var caller = new List<Expr>();
for (int i = 0; i < N; i++) {
Expression e0 = Substitute(calleeDecreases[i], receiverReplacement, substMap);
Expression e1 = contextDecreases[i];
- if (!CompatibleDecreasesTypes(cce.NonNull(e0.Type), cce.NonNull(e1.Type))) {
+ if (!CompatibleDecreasesTypes(e0.Type, e1.Type)) {
N = i;
break;
}
@@ -7048,7 +7048,7 @@ namespace Microsoft.Dafny {
/// ee0 represents the new values and ee1 represents old values.
/// If builder is non-null, then the check '0 ATMOST decr' is generated to builder.
/// </summary>
- Bpl.Expr DecreasesCheck(List<IToken/*!*/>/*!*/ toks, List<Type/*!*/>/*!*/ types0, List<Type/*!*/>/*!*/ types1, List<Bpl.Expr/*!*/>/*!*/ ee0, List<Bpl.Expr/*!*/>/*!*/ ee1,
+ Bpl.Expr DecreasesCheck(List<IToken> toks, List<Type> types0, List<Type> types1, List<Bpl.Expr> ee0, List<Bpl.Expr> ee1,
Bpl.StmtListBuilder builder, string suffixMsg, bool allowNoChange, bool includeLowerBound)
{
Contract.Requires(cce.NonNullElements(toks));
@@ -7114,6 +7114,8 @@ namespace Microsoft.Dafny {
bool CompatibleDecreasesTypes(Type t, Type u) {
Contract.Requires(t != null);
Contract.Requires(u != null);
+ t = t.NormalizeExpand();
+ u = u.NormalizeExpand();
if (t is BoolType) {
return u is BoolType;
} else if (t is IntType) {
@@ -7146,7 +7148,7 @@ namespace Microsoft.Dafny {
else return null;
}
- void ComputeLessEq(IToken/*!*/ tok, Type/*!*/ ty0, Type/*!*/ ty1, Bpl.Expr/*!*/ e0, Bpl.Expr/*!*/ e1, out Bpl.Expr/*!*/ less, out Bpl.Expr/*!*/ atmost, out Bpl.Expr/*!*/ eq, bool includeLowerBound)
+ void ComputeLessEq(IToken tok, Type ty0, Type ty1, Bpl.Expr e0, Bpl.Expr e1, out Bpl.Expr less, out Bpl.Expr atmost, out Bpl.Expr eq, bool includeLowerBound)
{
Contract.Requires(tok != null);
Contract.Requires(ty0 != null);
@@ -7158,8 +7160,10 @@ namespace Microsoft.Dafny {
Contract.Ensures(Contract.ValueAtReturn(out atmost)!=null);
Contract.Ensures(Contract.ValueAtReturn(out eq)!=null);
- Nullable<BuiltinFunction> rk0 = RankFunction(ty0);
- Nullable<BuiltinFunction> rk1 = RankFunction(ty1);
+ ty0 = ty0.NormalizeExpand();
+ ty1 = ty1.NormalizeExpand();
+ var rk0 = RankFunction(ty0);
+ var rk1 = RankFunction(ty1);
if (rk0 != null && rk1 != null && rk0 != rk1) {
eq = Bpl.Expr.False;
Bpl.Expr b0 = FunctionCall(tok, rk0.Value, null, e0);
diff --git a/Test/dafny0/EqualityTypes.dfy.expect b/Test/dafny0/EqualityTypes.dfy.expect
index 186c53be..fde9aadf 100644
--- a/Test/dafny0/EqualityTypes.dfy.expect
+++ b/Test/dafny0/EqualityTypes.dfy.expect
@@ -1,9 +1,9 @@
EqualityTypes.dfy(34,13): Error: a type declaration that requires equality support cannot be replaced by a codatatype
-EqualityTypes.dfy(35,11): Error: datatype 'Y' is used to refine an arbitrary type with equality support, but 'Y' does not support equality
-EqualityTypes.dfy(40,11): Error: arbitrary type 'X' is not allowed to be replaced by a datatype that takes a different number of type parameters
-EqualityTypes.dfy(41,8): Error: arbitrary type 'Y' is not allowed to be replaced by a class that takes a different number of type parameters
-EqualityTypes.dfy(45,11): Error: datatype 'X' is used to refine an arbitrary type with equality support, but 'X' does not support equality
-EqualityTypes.dfy(46,11): Error: datatype 'Y' is used to refine an arbitrary type with equality support, but 'Y' does not support equality
+EqualityTypes.dfy(35,11): Error: type 'Y' is used to refine an arbitrary type with equality support, but 'Y' does not support equality
+EqualityTypes.dfy(40,11): Error: arbitrary type 'X' is not allowed to be replaced by a type that takes a different number of type parameters (got 1, expected 0)
+EqualityTypes.dfy(41,8): Error: arbitrary type 'Y' is not allowed to be replaced by a class that takes a different number of type parameters (got 1, expected 0)
+EqualityTypes.dfy(45,11): Error: type 'X' is used to refine an arbitrary type with equality support, but 'X' does not support equality
+EqualityTypes.dfy(46,11): Error: type 'Y' is used to refine an arbitrary type with equality support, but 'Y' does not support equality
EqualityTypes.dfy(66,7): Error: == can only be applied to expressions of types that support equality (got Dt<T>)
EqualityTypes.dfy(85,8): Error: type parameter 0 (T) passed to method M must support equality (got _T0)
EqualityTypes.dfy(109,7): Error: == can only be applied to expressions of types that support equality (got D)
diff --git a/Test/dafny0/TypeInstantiations.dfy b/Test/dafny0/TypeInstantiations.dfy
new file mode 100644
index 00000000..cbe6d423
--- /dev/null
+++ b/Test/dafny0/TypeInstantiations.dfy
@@ -0,0 +1,58 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+abstract module M0 {
+ type A
+ type B = int
+ type C(==)
+ type D(==)
+ type E(==)
+ type F(==)
+
+ type G
+ type H<X,Y>
+ type J<Z>
+
+ type K0<W(==)>
+ type K1<W(==)>
+ type L<V>
+ type M(==)<U>
+ type N(==)<U>
+ type O(==)<U>
+ type P<U>
+ type R<U>
+ type S<U>
+ type T
+
+ type TP0
+ type TP1<Y0>
+ type TP2<Y0,Y1>
+}
+module M1 refines M0 {
+ type A = int
+ type B // error: cannot change a type synonym into an opaque type
+ datatype C = MakeC(ghost x: int, y: int) // error: this type does not support equality
+ type D = C // error: this type does not support equality
+ codatatype E = More(bool, E) // error: this type does not support equality
+ datatype List<T> = Nil | Cons(T, List)
+ type F = List<real> // fine
+
+ type G<X0> = List<X0> // error: G is not allowed to take type parameters
+ type H<X1> = List<X1> // error: H needs two type parameters
+ type J = List<real> // error: J needs one type parameter
+
+ type K0<W> = List<W>
+ type K1<W>
+ type L<V(==)> = List<V> // fine
+ type M<U'> = int // fine, because M<U'> does support equality
+ type N<U'> = List<U'> // error: N<U'> does not support equality
+ type O<U'(==)> = List<U'> // fine
+ type P<U'> = List<U'> // fine
+ class R { } // error: wrong number of type arguments
+ class S<T> { }
+ class T<T> { } // error: wrong number of type arguments
+
+ type TP0<E0> // error: wrong number of type arguments
+ type TP1 // error: wrong number of type arguments
+ type TP2<E0,E1>
+}
diff --git a/Test/dafny0/TypeInstantiations.dfy.expect b/Test/dafny0/TypeInstantiations.dfy.expect
new file mode 100644
index 00000000..6c214970
--- /dev/null
+++ b/Test/dafny0/TypeInstantiations.dfy.expect
@@ -0,0 +1,13 @@
+TypeInstantiations.dfy(33,7): Error: an arbitrary type declaration (B) in a refining module cannot replace a more specific type declaration in the refinement base
+TypeInstantiations.dfy(36,13): Error: a type declaration that requires equality support cannot be replaced by a codatatype
+TypeInstantiations.dfy(40,7): Error: arbitrary type 'G' is not allowed to be replaced by a type that takes a different number of type parameters (got 1, expected 0)
+TypeInstantiations.dfy(41,7): Error: arbitrary type 'H' is not allowed to be replaced by a type that takes a different number of type parameters (got 1, expected 2)
+TypeInstantiations.dfy(42,7): Error: arbitrary type 'J' is not allowed to be replaced by a type that takes a different number of type parameters (got 0, expected 1)
+TypeInstantiations.dfy(51,8): Error: arbitrary type 'R' is not allowed to be replaced by a type that takes a different number of type parameters (got 0, expected 1)
+TypeInstantiations.dfy(53,8): Error: arbitrary type 'T' is not allowed to be replaced by a type that takes a different number of type parameters (got 1, expected 0)
+TypeInstantiations.dfy(55,7): Error: type 'TP0' is not allowed to change its number of type parameters (got 1, expected 0)
+TypeInstantiations.dfy(56,7): Error: type 'TP1' is not allowed to change its number of type parameters (got 0, expected 1)
+TypeInstantiations.dfy(34,11): Error: type 'C' is used to refine an arbitrary type with equality support, but 'C' does not support equality
+TypeInstantiations.dfy(35,7): Error: type 'D' is used to refine an arbitrary type with equality support, but 'D' does not support equality
+TypeInstantiations.dfy(48,7): Error: type 'N' is used to refine an arbitrary type with equality support, but 'N' does not support equality
+12 resolution/type errors detected in TypeInstantiations.dfy