Skip to content

Commit 935fea7

Browse files
authored
Merge pull request #5178 from Jasper-M/fix/5044
Fix #5044: guard against forward references in the TypeTree of New trees
2 parents 8cc445b + 91eaf20 commit 935fea7

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,14 @@ class RefChecks extends MiniPhase { thisPhase =>
10101010
}
10111011

10121012
override def transformNew(tree: New)(implicit ctx: Context) = {
1013-
val sym = tree.tpe.typeSymbol
1013+
val tpe = tree.tpe
1014+
val sym = tpe.typeSymbol
10141015
checkUndesiredProperties(sym, tree.pos)
10151016
currentLevel.enterReference(sym, tree.pos)
1017+
tpe.dealias.foreachPart {
1018+
case TermRef(_, s: Symbol) => currentLevel.enterReference(s, tree.pos)
1019+
case _ =>
1020+
}
10161021
tree
10171022
}
10181023
}
@@ -1643,4 +1648,3 @@ class RefChecks extends MiniPhase { thisPhase =>
16431648
}
16441649
}
16451650
*/
1646-

tests/neg/i5044.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class I0 {
2+
class I1
3+
def test0 = {
4+
val x = new y.I1 // error: `y` is a forward reference extending over the definition of `x`
5+
val y = new I0
6+
}
7+
8+
def test1 = {
9+
type T = y.I1
10+
val x = new T // error: `y` is a forward reference extending over the definition of `x`
11+
val y = new I0
12+
}
13+
14+
class I2[T1, T2]
15+
def test2 = {
16+
type A[T] = y.I2[T, String]
17+
val x = new A[Int] // error: `y` is a forward reference extending over the definition of `x`
18+
val y = new I0
19+
}
20+
21+
def test3 = {
22+
val x = new T // error: `T` is a forward reference extending over the definition of `x`
23+
val y = new I0
24+
type T = y.I1
25+
}
26+
}

0 commit comments

Comments
 (0)