-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Strange type checking error for extractors #2378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes, that's what dotty requires. The error message is pretty specific: You can't mention a private member in a public type. |
You need to replace |
Adding 23 | case Apply(fun, args) => 3
| ^^^^^
| not found: type Apply
longer explanation available when compiling with `-explain`
-- [E006] Unbound Identifier Error: examples/abstract.scala:27:9 ---------------
27 | case Apply(fun, args) => 3
| ^^^^^
| not found: type Apply |
It seems to do with the overloaded extractor, if I remove the overloaded extractor, everything works fine: trait Cap
trait Toolbox {
type Tree
val tpd: TypedTrees
trait TypedTrees {
type Tree
}
val Apply: ApplyImpl
trait ApplyImpl {
def unapply(tree: Tree): Option[(Tree, Seq[Tree])]
// def unapply(tree: tpd.Tree)(implicit c: Cap): Option[(tpd.Tree, Seq[tpd.Tree])]
}
}
class Test(val tb: Toolbox) {
import tb._
implicit val cap: Cap = null
def foo(tree: Tree): Int = tree match {
case Apply(fun, args) => 3
}
// def bar(tree: tpd.Tree): Int = tree match {
// case Apply(fun, args) => 3
// }
} |
Just checked, #2358 also fixes this bug, it's due to incorrect widening of the selector. |
While the PR #2358 fixed this specific problem by avoiding incorrect widening. There's a deeper bug in the compiler about error reporting for ambiguous overloaded extractors: trait Cap
trait Tree
object Apply {
def unapply(tree: Tree): Option[(Tree, Seq[Tree])] = ???
def unapply(tree: Tree)(implicit c: Cap): Option[(Tree, Seq[Tree])] = ???
}
class Test {
def foo(tree: Tree): Int = tree match {
case Apply(fun, args) => 3
}
} An 11 | case Apply(fun, args) => 3
| ^^^^^
| not found: type Apply The root cause is that in
The problem is that in the case above, we expect the typer to report the error message from the first step, instead it reports error message from the last try while typing |
The following code type checks fine in Scalac, but failed in Dotty.
Error message:
The text was updated successfully, but these errors were encountered: