Skip to content

Commit c70366d

Browse files
committed
Always ignore type in selectionProto
The type of a SelectionProto needs to be ignorable because there might be an implicit conversion on the selection. E.g. implicit def a2b(x: A): B = ??? val x: { a: A } = ??? val b: B = x.a This was previously handled by allowing implicit conversions in compatibility checks. But it turns out we can afford to ignore the type of a selectProto and unignore on ambiguities later.
1 parent e43c3aa commit c70366d

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ object ProtoTypes {
7979
}
8080

8181
/** A class marking ignored prototypes that can be reviealed by `deepenProto` */
82-
case class IgnoredProto(proto: ProtoType) extends UncachedGroundType with MatchAlways {
83-
override def deepenProto(implicit ctx: Context): Type = proto
82+
case class IgnoredProto(ignored: Type) extends UncachedGroundType with MatchAlways {
83+
override def deepenProto(implicit ctx: Context): Type = ignored
8484
}
8585

8686
def ignoreIfProto(tp: Type): Type = tp match {
@@ -145,7 +145,7 @@ object ProtoTypes {
145145
if (name.isConstructorName) WildcardType
146146
else tp match {
147147
case tp: UnapplyFunProto => new UnapplySelectionProto(name)
148-
case tp => SelectionProto(name, ignoreIfProto(tp), typer)
148+
case tp => SelectionProto(name, IgnoredProto(tp), typer)
149149
}
150150

151151
/** A prototype for expressions [] that are in some unspecified selection operation
@@ -416,7 +416,7 @@ object ProtoTypes {
416416
object dummyTreeOfType {
417417
def apply(tp: Type): Tree = dummyTree withTypeUnchecked tp
418418
def unapply(tree: Tree): Option[Type] = tree match {
419-
case Literal(Constant(null)) => Some(tree.tpe)
419+
case Literal(Constant(null)) => Some(tree.typeOpt)
420420
case _ => None
421421
}
422422
}

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
957957
}
958958
}
959959

960-
def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = /*>|>*/ ctx.traceIndented (i"typing $tree, patternMode = ${ctx.mode is Mode.Pattern}", typr, show = true) /*<|<*/ {
960+
def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = /*>|>*/ ctx.traceIndented (i"typing $tree", typr, show = true) /*<|<*/ {
961961
assertPositioned(tree)
962962
try adapt(typedUnadapted(tree, pt), pt, tree)
963963
catch {

tests/pos/implicitonSelect.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object test {
2+
class A
3+
class B
4+
implicit def a2b(x: A): B = new B
5+
class ARef { val a: A = new A }
6+
val x = new ARef
7+
val b: B = x.a
8+
}

0 commit comments

Comments
 (0)