diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 5f04152c62b1..d25617da85c8 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -1010,9 +1010,14 @@ class RefChecks extends MiniPhase { thisPhase => } override def transformNew(tree: New)(implicit ctx: Context) = { - val sym = tree.tpe.typeSymbol + val tpe = tree.tpe + val sym = tpe.typeSymbol checkUndesiredProperties(sym, tree.pos) currentLevel.enterReference(sym, tree.pos) + tpe.dealias.foreachPart { + case TermRef(_, s: Symbol) => currentLevel.enterReference(s, tree.pos) + case _ => + } tree } } @@ -1643,4 +1648,3 @@ class RefChecks extends MiniPhase { thisPhase => } } */ - diff --git a/tests/neg/i5044.scala b/tests/neg/i5044.scala new file mode 100644 index 000000000000..efcfdd31db64 --- /dev/null +++ b/tests/neg/i5044.scala @@ -0,0 +1,26 @@ +class I0 { + class I1 + def test0 = { + val x = new y.I1 // error: `y` is a forward reference extending over the definition of `x` + val y = new I0 + } + + def test1 = { + type T = y.I1 + val x = new T // error: `y` is a forward reference extending over the definition of `x` + val y = new I0 + } + + class I2[T1, T2] + def test2 = { + type A[T] = y.I2[T, String] + val x = new A[Int] // error: `y` is a forward reference extending over the definition of `x` + val y = new I0 + } + + def test3 = { + val x = new T // error: `T` is a forward reference extending over the definition of `x` + val y = new I0 + type T = y.I1 + } +}