Skip to content

Commit cd64175

Browse files
authored
Fixing type checking for predicate instance plugin (#835)
1 parent 9b2c33e commit cd64175

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

Diff for: src/main/scala/viper/silver/plugin/standard/predicateinstance/PredicateInstancePASTExtension.scala

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ case class PPredicateInstance(m: PReserved[PMarkerSymbol.type], idnuse: PIdnRef[
2222

2323
typ = PPrimitiv(PReserved(PPredicateInstanceKeyword)(NoPosition, NoPosition))(NoPosition, NoPosition)
2424

25-
// TODO: Don't know if this is correct
26-
private val _typeSubstitutions = new scala.collection.mutable.ArrayDeque[PTypeSubstitution]()
25+
private var _typeSubstitutions = new scala.collection.mutable.ArrayDeque[PTypeSubstitution]()
2726
final override def typeSubstitutions: mutable.ArrayDeque[PTypeSubstitution] = _typeSubstitutions
28-
override def forceSubstitution(ts: PTypeSubstitution): Unit = {}
27+
override def forceSubstitution(ts: PTypeSubstitution): Unit = {
28+
args.inner.toSeq.foreach(_.forceSubstitution(ts))
29+
}
2930

3031
override def typecheck(t: TypeChecker, n: NameAnalyser): Option[Seq[String]] = {
3132
if (idnuse.decls.isEmpty)
@@ -36,6 +37,7 @@ case class PPredicateInstance(m: PReserved[PMarkerSymbol.type], idnuse: PIdnRef[
3637
// type checking should be the same as for PPredicateAccess nodes
3738
val predicateAccess = PCall(idnuse.retype(), args, None)(pos)
3839
t.checkInternal(predicateAccess)
40+
_typeSubstitutions = predicateAccess.typeSubstitutions
3941
None
4042
}
4143
}

Diff for: src/test/resources/all/issues/silver/0835.vpr

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
5+
domain Tuple2[T0, T1] {
6+
7+
function get0of2(p: Tuple2[T0, T1]): T0
8+
9+
function get1of2(p: Tuple2[T0, T1]): T1
10+
11+
function tuple2(t0: T0, t1: T1): Tuple2[T0, T1]
12+
13+
axiom getter_over_tuple2 {
14+
(forall t0: T0, t1: T1 ::
15+
{ (tuple2(t0, t1): Tuple2[T0, T1]) }
16+
(get0of2((tuple2(t0, t1): Tuple2[T0, T1])): T0) == t0 &&
17+
(get1of2((tuple2(t0, t1): Tuple2[T0, T1])): T1) == t1)
18+
}
19+
20+
axiom tuple2_over_getter {
21+
(forall p: Tuple2[T0, T1] ::
22+
{ (get0of2(p): T0) }
23+
{ (get1of2(p): T1) }
24+
(tuple2((get0of2(p): T0), (get1of2(p): T1)): Tuple2[T0, T1]) == p)
25+
}
26+
}
27+
28+
domain Poly[T] {
29+
30+
function box_Poly(x: T): Ref
31+
32+
function unbox_Poly(y: Ref): T
33+
34+
axiom {
35+
(forall x: T ::
36+
{ (box_Poly(x): Ref) }
37+
(unbox_Poly((box_Poly(x): Ref)): T) == x)
38+
}
39+
}
40+
41+
domain Types {
42+
function Errno_8b6e126d_T_Types(): Types
43+
}
44+
45+
function DefinedErrno_8b6e126d_T$$$$_E_$$$_IsDuplicableMem_8b6e126d_MErrno_IsDuplicableMem_ad177c4e_SY$db8f20c_ad177c4e__proof(e_V0: Int): Bool
46+
requires acc(dynamic_pred_0((tuple2((box_Poly(e_V0): Ref), Errno_8b6e126d_T_Types()): Tuple2[Ref, Types])), wildcard)
47+
decreases dynamic_pred_0((tuple2((box_Poly(e_V0): Ref), Errno_8b6e126d_T_Types()): Tuple2[Ref, Types]))
48+
49+
50+
predicate dynamic_pred_0(i: Tuple2[Ref, Types])

0 commit comments

Comments
 (0)