diff options
author | Martin Odersky <odersky@gmail.com> | 2014-05-18 13:17:07 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-05-30 14:43:39 +0200 |
commit | c70366db8469e81e315fe89672e8321607a7310a (patch) | |
tree | 6d0c551ef974121041c578c89c41184182eb065b | |
parent | e43c3aaa61e570de1cb80b1766fb3e3988c444a0 (diff) | |
download | dotty-c70366db8469e81e315fe89672e8321607a7310a.tar.gz dotty-c70366db8469e81e315fe89672e8321607a7310a.tar.bz2 dotty-c70366db8469e81e315fe89672e8321607a7310a.zip |
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.
-rw-r--r-- | src/dotty/tools/dotc/typer/ProtoTypes.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 2 | ||||
-rw-r--r-- | tests/pos/implicitonSelect.scala | 8 |
3 files changed, 13 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 8bbd3d5d9..76fe1af31 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -79,8 +79,8 @@ object ProtoTypes { } /** A class marking ignored prototypes that can be reviealed by `deepenProto` */ - case class IgnoredProto(proto: ProtoType) extends UncachedGroundType with MatchAlways { - override def deepenProto(implicit ctx: Context): Type = proto + case class IgnoredProto(ignored: Type) extends UncachedGroundType with MatchAlways { + override def deepenProto(implicit ctx: Context): Type = ignored } def ignoreIfProto(tp: Type): Type = tp match { @@ -145,7 +145,7 @@ object ProtoTypes { if (name.isConstructorName) WildcardType else tp match { case tp: UnapplyFunProto => new UnapplySelectionProto(name) - case tp => SelectionProto(name, ignoreIfProto(tp), typer) + case tp => SelectionProto(name, IgnoredProto(tp), typer) } /** A prototype for expressions [] that are in some unspecified selection operation @@ -416,7 +416,7 @@ object ProtoTypes { object dummyTreeOfType { def apply(tp: Type): Tree = dummyTree withTypeUnchecked tp def unapply(tree: Tree): Option[Type] = tree match { - case Literal(Constant(null)) => Some(tree.tpe) + case Literal(Constant(null)) => Some(tree.typeOpt) case _ => None } } diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 32680e34b..0293d1803 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -957,7 +957,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - 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) /*<|<*/ { + def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = /*>|>*/ ctx.traceIndented (i"typing $tree", typr, show = true) /*<|<*/ { assertPositioned(tree) try adapt(typedUnadapted(tree, pt), pt, tree) catch { diff --git a/tests/pos/implicitonSelect.scala b/tests/pos/implicitonSelect.scala new file mode 100644 index 000000000..4f5f90ada --- /dev/null +++ b/tests/pos/implicitonSelect.scala @@ -0,0 +1,8 @@ +object test { + class A + class B + implicit def a2b(x: A): B = new B + class ARef { val a: A = new A } + val x = new ARef + val b: B = x.a +} |