Skip to content

Commit 84d4671

Browse files
committed
SI-8869 Prevent ill-kindedness in type lambdas
When type checking an type application, the arguments are allowed to be of kinds other than *. This leniency is controlled by the `ContextMode` bit `TypeConstructorAllowed`. (More fine grained checking of matching arity a bounds of type constructors is deferred until the refchecks phase to avoid cycles during typechecking.) However, this bit is propagated to child contexts, which means that we fail to report this error in the lexical context marked here: T[({type x = Option}#x)] `-------------' This commit resets this bit to false in any child context relates to a different tree from its parent.
1 parent a52db7f commit 84d4671

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ trait Contexts { self: Analyzer =>
480480
// SI-8245 `isLazy` need to skip lazy getters to ensure `return` binds to the right place
481481
c.enclMethod = if (isDefDef && !owner.isLazy) c else enclMethod
482482

483+
if (tree != outer.tree) c(TypeConstructorAllowed) = false
484+
483485
registerContext(c.asInstanceOf[analyzer.Context])
484486
debuglog("[context] ++ " + c.unit + " / " + tree.summaryString)
485487
c

test/files/neg/t8869.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
t8869.scala:5: error: class Option takes type parameters
2+
def value: TC[({type l1[x] = Option})#l1] = ??? // error not reported!
3+
^
4+
t8869.scala:7: error: class Option takes type parameters
5+
type l2[x] = Option // error correctly reported
6+
^
7+
two errors found

test/files/neg/t8869.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class TC[T[_]] {
2+
def identity[A](a: T[A]): T[A] = a
3+
}
4+
object Test {
5+
def value: TC[({type l1[x] = Option})#l1] = ??? // error not reported!
6+
7+
type l2[x] = Option // error correctly reported
8+
def value1: TC[l2] = ???
9+
}
10+

0 commit comments

Comments
 (0)