Skip to content

Commit 93c4470

Browse files
committed
added tests for new errors
1 parent f468e96 commit 93c4470

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

Source/Concurrency/LinearDomainCollector.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public LinearDomain(Program program, Type permissionType)
5757
}
5858
}
5959

60-
class LinearDomainCollector : ReadOnlyVisitor
60+
class LinearDomainCollector
6161
{
6262
private LinearTypeChecker linearTypeChecker;
6363
private Program program => linearTypeChecker.program;
@@ -137,8 +137,7 @@ private void CreatePermissionCollectors(Dictionary<Type, HashSet<Type>> linearTy
137137
[],
138138
[collectionTarget],
139139
VarHelper.Formal("perm", TypeHelper.MapType(permissionType, Type.Bool), false),
140-
null,
141-
new QKeyValue(Token.NoToken, "inline", new List<object>(), null));
140+
null);
142141
collectors[ctorType].Add(permissionType, collectorFunction);
143142
program.AddTopLevelDeclaration(collectorFunction);
144143
}

Source/Concurrency/LinearTypeCollector.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,24 @@ private void Collect()
3838
}
3939
}
4040

41+
private Type OriginalType(Type type)
42+
{
43+
if (type is not CtorType ctorType)
44+
{
45+
return type;
46+
}
47+
var originalTypeCtorDecl = Monomorphizer.GetOriginalDecl(ctorType.Decl);
48+
var actualTypeParams = program.monomorphizer.GetTypeInstantiation(ctorType.Decl);
49+
if (actualTypeParams == null)
50+
{
51+
return type;
52+
}
53+
return new CtorType(Token.NoToken, originalTypeCtorDecl, actualTypeParams.Select(t => OriginalType(t)).ToList());
54+
}
55+
4156
private void Check()
4257
{
43-
foreach (var datatypeTypeCtorDecl in linearTypes.Keys.OfType<CtorType>().Select(ctorType => ctorType.Decl).OfType<DatatypeTypeCtorDecl>())
58+
foreach (var datatypeTypeCtorDecl in program.TopLevelDeclarations.OfType<DatatypeTypeCtorDecl>())
4459
{
4560
var originalTypeCtorDecl = Monomorphizer.GetOriginalDecl(datatypeTypeCtorDecl);
4661
var actualTypeParams = program.monomorphizer.GetTypeInstantiation(datatypeTypeCtorDecl);
@@ -50,15 +65,15 @@ private void Check()
5065
var innerType = actualTypeParams[0];
5166
if (linearTypes.ContainsKey(innerType))
5267
{
53-
checkingContext.Error(originalTypeCtorDecl, "One instantiated with a linear type");
68+
checkingContext.Error(originalTypeCtorDecl, $"One instantiated with a linear type: {OriginalType(innerType)}");
5469
}
5570
}
5671
else if (typeName == "Map")
5772
{
5873
var keyType = actualTypeParams[0];
5974
if (!IsOneType(keyType) && linearTypes.ContainsKey(keyType))
6075
{
61-
checkingContext.Error(originalTypeCtorDecl, "Map instantiated with a key type that is neither One _ nor ordinary");
76+
checkingContext.Error(originalTypeCtorDecl, $"Map instantiated with a key type that is neither One _ nor ordinary: {OriginalType(keyType)}");
6277
}
6378
}
6479
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %parallel-boogie -lib:base "%s" > "%t"
2+
// RUN: %diff "%s.expect" "%t"
3+
4+
datatype A<T> { A(x: One T) }
5+
6+
procedure P0(a: A int) returns ({:linear} b: One (A int)) {
7+
b := One(a);
8+
}
9+
10+
procedure P1(a: Map (A int) int) {
11+
12+
}
13+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
base.bpl(285,9): Error: One instantiated with a linear type: A int
2+
base.bpl(212,9): Error: Map instantiated with a key type that is neither One _ nor ordinary: A int
3+
2 type checking errors detected in type-inst-errors.bpl

0 commit comments

Comments
 (0)