Skip to content

Commit 7f9f784

Browse files
authored
Fixed type resolution crash (#992)
Type resolution crashes if there is an unknown type name. This PR makes a change so that this unknown name is resolved to bool type to allow type resolution to continue safely.
1 parent 3a23efe commit 7f9f784

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed

Source/Core/AST/AbsyType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,8 +1678,8 @@ public override Type ResolveType(ResolutionContext rc)
16781678
}
16791679

16801680
// otherwise: this name is not declared anywhere
1681-
rc.Error(this, "undeclared type: {0}", Name);
1682-
return this;
1681+
rc.Error(this, "undeclared type: {0} (replacing with \"bool\" to continue resolving)", Name);
1682+
return Type.Bool;
16831683
}
16841684

16851685
private List<Type> ResolveArguments(ResolutionContext rc)

Test/bitvectors/bv2.bpl.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
bv2.bpl(6,13): Error: bitvector bounds in illegal position
2-
bv2.bpl(8,13): Error: undeclared type: x
2+
bv2.bpl(8,13): Error: undeclared type: x (replacing with "bool" to continue resolving)
33
bv2.bpl(9,14): Error: bitvector bounds in illegal position
44
3 name resolution errors detected in bv2.bpl

Test/civl/large-samples/shared-vector.bpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ modifies IntArrayPool;
3838
}
3939
yield procedure {:layer 2} IntArray_Alloc(v: Vec int) returns (loc_iv: Loc)
4040
refines Atomic_IntArray_Alloc;
41+
ensures call Yield(loc_iv);
4142
preserves call IntArrayDom();
4243
{
4344
var {:linear} one_loc_mutex: One Loc;
@@ -56,7 +57,7 @@ preserves call IntArrayDom();
5657
call {:layer 2} OldMutexPool := Copy(MutexPool);
5758
i := 0;
5859
while (i < Vec_Len(v))
59-
invariant {:layer 2} 0 <= i;
60+
invariant {:layer 2} 0 <= i && i <= Vec_Len(v);
6061
invariant {:layer 2} mutexes->dom == values->dom;
6162
invariant {:layer 2} mutexes->dom->val == (lambda j: int :: 0 <= j && j < i);
6263
invariant {:layer 2} (forall j: int:: 0 <= j && j < i ==> Map_Contains(MutexPool, Map_At(mutexes, j)->val));

Test/civl/large-samples/treiber-stack.bpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ modifies TreiberPool;
7070
}
7171
yield procedure {:layer 4} Alloc() returns (loc_t: Loc)
7272
refines AtomicAlloc;
73+
ensures call TopInStack(loc_t);
74+
ensures call ReachInStack(loc_t);
7375
preserves call StackDom();
7476
{
7577
var top: Option LocTreiberNode;

Test/test0/Types1.bpl.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Types1.bpl(8,11): Error: undeclared type: x
2-
Types1.bpl(9,11): Error: undeclared type: x
3-
Types1.bpl(9,14): Error: undeclared type: x
1+
Types1.bpl(8,11): Error: undeclared type: x (replacing with "bool" to continue resolving)
2+
Types1.bpl(9,11): Error: undeclared type: x (replacing with "bool" to continue resolving)
3+
Types1.bpl(9,14): Error: undeclared type: x (replacing with "bool" to continue resolving)
44
3 name resolution errors detected in Types1.bpl

Test/test20/Prog0.bpl.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Prog0.bpl(19,10): Error: type variable must occur in map arguments: a
22
Prog0.bpl(31,27): Error: more than one declaration of type variable: beta
3-
Prog0.bpl(34,22): Error: undeclared type: alpha
4-
Prog0.bpl(35,35): Error: undeclared type: alpha
3+
Prog0.bpl(34,22): Error: undeclared type: alpha (replacing with "bool" to continue resolving)
4+
Prog0.bpl(35,35): Error: undeclared type: alpha (replacing with "bool" to continue resolving)
55
4 name resolution errors detected in Prog0.bpl

Test/test20/TypeDecls0.bpl.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ TypeDecls0.bpl(15,12): Error: more than one declaration of type variable: a
33
TypeDecls0.bpl(16,18): Error: more than one declaration of type variable: a
44
TypeDecls0.bpl(20,17): Error: type variable must occur in map arguments: b
55
TypeDecls0.bpl(24,9): Error: type constructor received wrong number of arguments: C
6-
TypeDecls0.bpl(26,9): Error: undeclared type: A0
7-
TypeDecls0.bpl(27,9): Error: undeclared type: F
6+
TypeDecls0.bpl(26,9): Error: undeclared type: A0 (replacing with "bool" to continue resolving)
7+
TypeDecls0.bpl(27,9): Error: undeclared type: F (replacing with "bool" to continue resolving)
88
TypeDecls0.bpl(30,9): Error: type constructor received wrong number of arguments: E
99
TypeDecls0.bpl(32,9): Error: type constructor received wrong number of arguments: E
1010
TypeDecls0.bpl(34,9): Error: type constructor received wrong number of arguments: E

0 commit comments

Comments
 (0)