From 146a362bf74418feeb18e12c34178819ecb64942 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 20 Dec 2013 11:33:05 +0100 Subject: Handling implicit unapply arguments. Changed format of UnApply nodes to also take implicit parameters. See doc comment in class Trees.UnApply --- src/dotty/tools/dotc/typer/Applications.scala | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/dotty/tools/dotc/typer/Applications.scala') diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index ad6bdd787..08987a095 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -629,7 +629,7 @@ trait Applications extends Compatibility { self: Typer => } unapply.tpe.widen match { - case mt: MethodType if !mt.isDependent => + case mt: MethodType if mt.paramTypes.length == 1 && !mt.isDependent => val unapplyArgType = mt.paramTypes.head println(s"unapp arg tpe = ${unapplyArgType.show}, pt = ${pt.show}") def wpt = widenForMatchSelector(pt) @@ -671,7 +671,15 @@ trait Applications extends Compatibility { self: Typer => i"Pattern type $unapplyArgType is neither a subtype nor a supertype of selector type $wpt", tree.pos) } - var argTypes = unapplyArgs(mt.resultType) + + val dummyArg = dummyTreeOfType(unapplyArgType) + val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapply, dummyArg :: Nil))) + val unapplyImplicits = unapplyApp match { + case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); args2 + case Apply(unapply, `dummyArg` :: Nil) => Nil + } + + var argTypes = unapplyArgs(unapplyApp.tpe) val bunchedArgs = argTypes match { case argType :: Nil if argType.isRepeatedParam => untpd.SeqLiteral(args) :: Nil case _ => args @@ -681,15 +689,15 @@ trait Applications extends Compatibility { self: Typer => argTypes = argTypes.take(args.length) ++ List.fill(argTypes.length - args.length)(WildcardType) } - val typedArgs = (bunchedArgs, argTypes).zipped map (typed(_, _)) - val result = cpy.UnApply(tree, unapply, typedArgs) withType ownType - println(s"typedargs = $typedArgs") + val unapplyPatterns = (bunchedArgs, argTypes).zipped map (typed(_, _)) + val result = cpy.UnApply(tree, unapply, unapplyImplicits, unapplyPatterns) withType ownType + println(s"unapply patterns = $unapplyPatterns") if ((ownType eq pt) || ownType.isError) result else Typed(result, TypeTree(ownType)) case tp => val unapplyErr = if (tp.isError) unapply else notAnExtractor(unapply) val typedArgsErr = args mapconserve (typed(_, defn.AnyType)) - cpy.UnApply(tree, unapplyErr, typedArgsErr) withType ErrorType + cpy.UnApply(tree, unapplyErr, Nil, typedArgsErr) withType ErrorType } } -- cgit v1.2.3