Permalink
Browse files

SI-8023 Fix symbol-completion-order type var pattern bug

Removing the `isComplete` check altogether leads to cycles in,
for instatnce, F-bound type parameters:

    trait LSO[+A, +Repr <: LSO[A, Repr]] // error: illegal cyclic reference involving type Repr

But, I believe that we can (and must) eagerly initialize the type
parameter symbols if we are typechecking a pattern.

While this appeared to regress in 2.11.x, but the problem was in fact
dormant and was merely uncovered in the fix for SI-7756, 3df1d77.
  • Loading branch information...
1 parent 073ebbd commit a89000be9f5b6506bcd891bd076700a9d1e79d01 @retronym retronym committed Dec 2, 2013
Showing with 37 additions and 7 deletions.
  1. +15 −7 src/compiler/scala/tools/nsc/typechecker/Typers.scala
  2. +22 −0 test/files/pos/t8023.scala
@@ -4879,14 +4879,22 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (sameLength(tparams, args)) {
// @M: kind-arity checking is done here and in adapt, full kind-checking is in checkKindBounds (in Infer)
- val args1 =
- if (!isComplete)
- args mapConserve (typedHigherKindedType(_, mode))
- // if symbol hasn't been fully loaded, can't check kind-arity
- else map2Conserve(args, tparams) { (arg, tparam) =>
- //@M! the polytype denotes the expected kind
- typedHigherKindedType(arg, mode, GenPolyType(tparam.typeParams, AnyTpe))
+ val args1 = map2Conserve(args, tparams) { (arg, tparam) =>
+ //@M! the polytype denotes the expected kind
+ def pt = GenPolyType(tparam.typeParams, AnyTpe)
+
+ // if symbol hasn't been fully loaded, can't check kind-arity
+ // ... except, if we're in a pattern, where we can and must (SI-8023)
+ if (mode.typingPatternOrTypePat) {
+ tparam.initialize
+ typedHigherKindedType(arg, mode, pt)
}
+ else if (isComplete)
+ typedHigherKindedType(arg, mode, pt)
+ else
+ // This overload (without pt) allows type constructors, as we don't don't know the allowed kind.
+ typedHigherKindedType(arg, mode)
+ }
val argtypes = args1 map (_.tpe)
foreach2(args, tparams) { (arg, tparam) =>
@@ -0,0 +1,22 @@
+import language._
+
+
+object Test {
+ def foo = (null: Any) match {
+ case a: A[k] =>
+ // error: kinds of the type arguments (k) do not conform to the
+ // expected kinds of the type parameters (type K) in class B.
+ new B[k]()
+ }
+}
+
+class A[K[L[_]]]
+
+class B[K[M[_]]]
+
+
+object Test2 {
+ def foo = (null: Any) match {
+ case a: A[k] => new B[k]() // this one worked before as the info of `A` was complete
+ }
+}

0 comments on commit a89000b

Please sign in to comment.