diff options
-rw-r--r-- | project/Build.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 21 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 4 | ||||
-rw-r--r-- | tests/pos/t1164.scala | 29 |
4 files changed, 14 insertions, 42 deletions
diff --git a/project/Build.scala b/project/Build.scala index 60b82e5f9..0ba9a454d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -6,7 +6,7 @@ object DottyBuild extends Build { val TRAVIS_BUILD = "dotty.travis.build" val agentOptions = List( - // "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", + "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" // "-agentpath:/home/dark/opt/yjp-2013-build-13072/bin/linux-x86-64/libyjpagent.so" ) diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 35a1ab3e9..b2572dcda 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -581,7 +581,7 @@ trait Applications extends Compatibility { self: Typer => assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs) } - def typedUnApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = track("typedUnApply") { + def typedUnApply(tree: untpd.Apply, selType: Type)(implicit ctx: Context): Tree = track("typedUnApply") { val Apply(qual, args) = tree def notAnExtractor(tree: Tree) = @@ -620,7 +620,7 @@ trait Applications extends Compatibility { self: Typer => */ def trySelectUnapply(qual: untpd.Tree)(fallBack: Tree => Tree): Tree = { val genericProto = new UnapplyFunProto(WildcardType, this) - def specificProto = new UnapplyFunProto(pt, this) + def specificProto = new UnapplyFunProto(selType, this) // try first for non-overloaded, then for overloaded ocurrences def tryWithName(name: TermName)(fallBack: Tree => Tree)(implicit ctx: Context): Tree = tryEither { @@ -662,20 +662,21 @@ trait Applications extends Compatibility { self: Typer => unapplyFn.tpe.widen match { case mt: MethodType if mt.paramTypes.length == 1 && !mt.isDependent => + val m = mt val unapplyArgType = mt.paramTypes.head - unapp.println(i"unapp arg tpe = $unapplyArgType, pt = $pt") - def wpt = widenForMatchSelector(pt) // needed? + unapp.println(i"unapp arg tpe = $unapplyArgType, pt = $selType") + def wpt = widenForMatchSelector(selType) // needed? val ownType = - if (pt <:< unapplyArgType) { - fullyDefinedType(unapplyArgType, "extractor argument", tree.pos) + if (selType <:< unapplyArgType) { + //fullyDefinedType(unapplyArgType, "extractor argument", tree.pos) unapp.println(i"case 1 $unapplyArgType ${ctx.typerState.constraint}") - pt + selType } else if (isSubTypeOfParent(unapplyArgType, wpt)) { maximizeType(unapplyArgType) match { case Some(tvar) => def msg = d"""There is no best instantiation of pattern type $unapplyArgType - |that makes it a subtype of selector type $pt. + |that makes it a subtype of selector type $selType. |Non-variant type variable ${tvar.origin} cannot be uniquely instantiated.""".stripMargin if (fromScala2x) { // We can't issue an error here, because in Scala 2, ::[B] is invariant @@ -702,7 +703,7 @@ trait Applications extends Compatibility { self: Typer => tree.pos) } - val dummyArg = dummyTreeOfType(unapplyArgType) + val dummyArg = dummyTreeOfType(ownType) val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil))) val unapplyImplicits = unapplyApp match { case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); args2 @@ -726,7 +727,7 @@ trait Applications extends Compatibility { self: Typer => val unapplyPatterns = (bunchedArgs, argTypes).zipped map (typed(_, _)) val result = assignType(cpy.UnApply(tree)(unapplyFn, unapplyImplicits, unapplyPatterns), ownType) unapp.println(s"unapply patterns = $unapplyPatterns") - if ((ownType eq pt) || ownType.isError) result + if ((ownType eq selType) || ownType.isError) result else Typed(result, TypeTree(ownType)) case tp => val unapplyErr = if (tp.isError) unapplyFn else notAnExtractor(unapplyFn) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 1823b09fa..7b8fe3727 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1050,8 +1050,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit typed(tree, pt)(ctx retractMode Mode.PatternOrType) def typedType(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = // todo: retract mode between Type and Pattern? typed(tree, pt)(ctx addMode Mode.Type) - def typedPattern(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = - typed(tree, pt)(ctx addMode Mode.Pattern) + def typedPattern(tree: untpd.Tree, selType: Type = WildcardType)(implicit ctx: Context): Tree = + typed(tree, selType)(ctx addMode Mode.Pattern) def tryEither[T](op: Context => T)(fallBack: (T, TyperState) => T)(implicit ctx: Context) = { val nestedCtx = ctx.fresh.setNewTyperState diff --git a/tests/pos/t1164.scala b/tests/pos/t1164.scala deleted file mode 100644 index ab58c1d6b..000000000 --- a/tests/pos/t1164.scala +++ /dev/null @@ -1,29 +0,0 @@ - - -object test { - - class Foo[a](val arg : a) - - object Foo { - def apply [a](arg : a, right :a) = new Foo[a](arg) - def unapply [a](m : Foo[a]) = Some (m.arg) - } - - def matchAndGetArgFromFoo[a]( e:Foo[a]):a = {e match { case Foo(x) => x }} - - - // Try the same thing as above but use function as argument to Bar - // constructor - - type FunIntToA [a] = (Int) => a - class Bar[a] (var f: FunIntToA[a]) - - object Bar { - def apply[a](f: FunIntToA[a]) = new Bar[a](f) - def unapply[a](m: Bar[a]) = Some (m.f) - } - - def matchAndGetFunFromBar[a](b:Bar[a]) : FunIntToA[a] = { b match { case Bar(x) => x}} - - -} |