-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Structural selection on intersection type leads to crash #2871
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
The issue is in def isStructuralTermSelect(tree: Tree)(implicit ctx: Context) = tree match {
case tree: Select =>
def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match {
case RefinedType(parent, rname, rinfo) =>
rname == tree.name || hasRefinement(parent)
case tp: TypeProxy =>
hasRefinement(tp.underlying)
case tp: OrType =>
hasRefinement(tp.tp1) || hasRefinement(tp.tp2)
case tp: AndType =>
hasRefinement(tp.tp1) && hasRefinement(tp.tp2)
case _ =>
false
}
!tree.symbol.exists && tree.isTerm && hasRefinement(tree.qualifier.tpe)
case _ =>
false
} A selection of a member |
As a workaround, you can make sure the structural member val c: { type A; val x: A } & { type A = Int; val x: A } = new Cont(1) |
When the fix is in, will the compiler crash if in the example we write
Why make it a type error? This would be weird, as it means having Besides, I think it's useful being able to use intersection types statically to talk about capabilities that types can have, without actually using runtime structural typing. |
No, it should raise an error and stop before the point where it could crash :).
Maybe not. The question is: should |
Well, the latter side is a proof that the field can be accessed without needing a runtime structural selection, so why not just pick that one? |
I worry that either solution might be surprising for users, but I guess picking the rule "always avoid structural selection if possible" is not too bad. |
Fix #2871: Recognize more types as structural selections
The following code:
... makes the compiler crash with:
The text was updated successfully, but these errors were encountered: