Skip to content

Commit 7071cd9

Browse files
committed
Better error message when unapply method is missing
1 parent e4e4810 commit 7071cd9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
814814
def followTypeAlias(tree: untpd.Tree): untpd.Tree = {
815815
tree match {
816816
case tree: untpd.RefTree =>
817-
val ttree = typedType(untpd.rename(tree, tree.name.toTypeName))
817+
val nestedCtx = ctx.fresh.setNewTyperState
818+
val ttree =
819+
typedType(untpd.rename(tree, tree.name.toTypeName))(nestedCtx)
818820
ttree.tpe match {
819-
case alias: TypeRef if alias.info.isAlias =>
821+
case alias: TypeRef if alias.info.isAlias && !nestedCtx.reporter.hasErrors =>
820822
companionRef(alias) match {
821823
case companion: TermRef => return untpd.ref(companion) withPos tree.pos
822824
case _ =>

tests/neg/i2378.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
trait Cap
2+
3+
trait Toolbox {
4+
type Tree
5+
6+
val tpd: TypedTrees
7+
trait TypedTrees {
8+
type Tree
9+
}
10+
11+
val Apply: ApplyImpl
12+
13+
trait ApplyImpl {
14+
def unapply(tree: Tree): Option[(Tree, Seq[Tree])]
15+
def unapply(tree: tpd.Tree)(implicit c: Cap): Option[(tpd.Tree, Seq[tpd.Tree])]
16+
}
17+
}
18+
19+
class Test(val tb: Toolbox) {
20+
import tb._
21+
implicit val cap: Cap = null
22+
23+
def foo(tree: Tree): Int = tree match { // error: private escape
24+
case tb.Apply(fun, args) => 3 // error
25+
}
26+
27+
def bar(tree: tpd.Tree): Int = tree match { // error: private escape
28+
case Apply(fun, args) => 3 // error
29+
}
30+
}

0 commit comments

Comments
 (0)