From fbdfc83b5f0b3a2d2962c1adad8875a7e58d6497 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 30 Sep 2015 16:09:04 +1000 Subject: SI-9498 Avoid caching bug with pattern type variables Typechecking a pattern that defines a pattern type variable initially assigns abstract type symbol with open type bounds. Later on, pattern type inference kicks in to sharpen the type of the variable based on constraints imposed by the expected type (ie, the type of scrutinee of the pattern.) However, before inference does this, a `TypeRef` to the abstract type symbol can be queried for its base type with respect to some class, which leads to it populating an internal cache. This cache becomes stale when the underlying symbol has its type mutated. The repercussions of this meant that a subsequent call to `baseType` gave the wrong result (`NoType`), which lead to an `asSeenFrom` operation to miss out of substitution of a type variable. Note the appearance of `A` in the old type errors in the enclosed test case. This commit takes an approach similar to 286dafbd to invalidate caches after the mutation. I've routed both bandaids through the same first aid kit: I'm sure over time we'll add additional calls to this method, and additional cache invalidations within it. --- test/files/pos/t9498.scala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/files/pos/t9498.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t9498.scala b/test/files/pos/t9498.scala new file mode 100644 index 0000000000..32fc01a806 --- /dev/null +++ b/test/files/pos/t9498.scala @@ -0,0 +1,25 @@ +trait Inv[A] { def head: A } +trait Cov[+A] { def head: A } + +class Test { + def inv(i: Inv[Inv[String]]) = i match { + case l: Inv[a] => + val x: a = l.head + x.head: String // okay + } + + def cov(c: Cov[Cov[String]]) = c match { + case l: Cov[a] => + val x: a = l.head + x.head: String // was: found A, required String + } + + def cov1(c: Cov[Cov[String]]) = c match { + case l: Cov[a] => l.head.head + } + cov1(null): String // was: found A, required String + + def cov3(c: Cov[Cov[String]]): String = c match { + case l: Cov[a] => val l1: l.type = l; l1.head.head + } +} -- cgit v1.2.3