Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
rname == tree.name || hasRefinement(parent)
case tp: TypeProxy =>
hasRefinement(tp.underlying)
case tp: OrType =>
case tp: AndOrType =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in assuming that if an intersection type has a component C that has a (non-structural) member f then a selection of .f on a value of that type will have its symbol filled in before isStructuralTermSelect is called?
Thus the condition !tree.symbol.exists below will not be satisfied, and we will not be issuing unnecessary structural selections. This is even if the type intersection also has a structural type containing a field f (on the other hand it seems like such types are consistently converted into refinements on C, e.g. C & {f:A} is represented as C{f:A} or just C if C#f =:= A).

hasRefinement(tp.tp1) || hasRefinement(tp.tp2)
case tp: AndType =>
hasRefinement(tp.tp1) && hasRefinement(tp.tp2)
case _ =>
false
}
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/i2871.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Cont[A0](x0: A0) { type A = A0; val x: A = x0 }
object Test {
val c: { type A; val x: A } & { type A = Int } = new Cont(1)
println(c.x : Int) // error: not an instance of Selectable
}