Skip to content

Commit 54cc764

Browse files
committed
Traverse the types to find undesired references
Undesired references can be to deprecated or experimental terms or types. Fixes #14034
1 parent 94f4118 commit 54cc764

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,18 @@ class RefChecks extends MiniPhase { thisPhase =>
13391339
}
13401340

13411341
override def transformTypeTree(tree: TypeTree)(using Context): TypeTree = {
1342-
checkExperimental(tree.symbol, tree.srcPos)
1342+
object CheckExperimental extends TypeTraverser {
1343+
def traverse(tp: Type): Unit =
1344+
tp match {
1345+
case tp: TypeRef =>
1346+
checkExperimental(tp.symbol, tree.srcPos)
1347+
case tp: TermRef =>
1348+
checkExperimental(tp.symbol, tree.srcPos)
1349+
case _ =>
1350+
traverseChildren(tp)
1351+
}
1352+
}
1353+
CheckExperimental.traverse(tree.tpe)
13431354
tree
13441355
}
13451356

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
@deprecated trait Exp
3+
@deprecated val exp = 1
4+
5+
def test1 = exp // error
6+
def test2(a: Exp) = () // error
7+
8+
type Foo0 = Exp // error
9+
type Foo = Option[Exp] // error
10+
type Bar = Option[exp.type] // error
11+
type Baz = Exp | Int // error
12+
type Quux = [X] =>> X match // error
13+
case Exp => Int
14+
type Quuz[A <: Exp] = Int // error
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import annotation.experimental
2+
3+
@experimental trait Exp
4+
@experimental val exp = 1
5+
6+
type Foo0 = Exp // error
7+
type Foo = Option[Exp] // error
8+
type Bar = Option[exp.type] // error
9+
type Baz = Exp | Int // error
10+
type Quux = [X] =>> X match // error
11+
case Exp => Int
12+
type Quuz[A <: Exp] = Int // error

0 commit comments

Comments
 (0)