From 6d4e71c111226591a4eeb5b77efac689ef1dd79a Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 18 Aug 2013 15:36:18 -0700 Subject: Refinement of name-based unapplySeq. Can't finnesse the drop method. Call it blindly for now, even though in the long run you won't have to write drop. --- .../tools/nsc/transform/patmat/MatchCodeGen.scala | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala index 8de8eb7d92..1b49b335c8 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala @@ -66,17 +66,17 @@ trait MatchCodeGen extends Interface { def tupleSel(binder: Symbol)(i: Int): Tree = (REF(binder) DOT nme.productAccessorName(i)) // make tree that accesses the i'th component of the tuple referenced by binder def index(tgt: Tree)(i: Int): Tree = tgt APPLY (LIT(i)) - private def definesDrop(tgt: Tree) = (tgt.tpe ne null) && (typeOfMemberNamedDrop(tgt.tpe) != NoType) - - // Right now this calls a direct drop member if it sees one, otherwise calls - // into the drop helper in ScalaRunTime. You should not actually have to write - // a method called drop for things to work, it's just not finished yet. - def drop(tgt: Tree)(n: Int): Tree = ( - if (definesDrop(tgt)) - Apply(Select(tgt, nme.drop), LIT(n) :: Nil) - else - gen.mkMethodCall(traversableDropMethod, tgt :: LIT(n) :: Nil) - ) + // Right now this blindly calls drop on the result of the unapplySeq + // unless it verifiably has no drop method (this is the case in particular + // with Array.) You should not actually have to write a method called drop + // for name-based matching, but this was an expedient route for the basics. + def drop(tgt: Tree)(n: Int): Tree = { + def callDirect = fn(tgt, nme.drop, LIT(n)) + def callRuntime = Apply(REF(traversableDropMethod), tgt :: LIT(n) :: Nil) + def needsRuntime = (tgt.tpe ne null) && (typeOfMemberNamedDrop(tgt.tpe) == NoType) + + if (needsRuntime) callRuntime else callDirect + } // NOTE: checker must be the target of the ==, that's the patmat semantics for ya def _equals(checker: Tree, binder: Symbol): Tree = checker MEMBER_== REF(binder) -- cgit v1.2.3