diff options
author | Paul Phillips <paulp@improving.org> | 2013-08-18 15:36:18 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-08-18 15:57:48 -0700 |
commit | 6d4e71c111226591a4eeb5b77efac689ef1dd79a (patch) | |
tree | 64bf11cafd20f69773517272f8077d79c5c6cef8 /src/compiler | |
parent | b3d9dfa9857aeb937a987536b3e2029d3be0030b (diff) | |
download | scala-6d4e71c111226591a4eeb5b77efac689ef1dd79a.tar.gz scala-6d4e71c111226591a4eeb5b77efac689ef1dd79a.tar.bz2 scala-6d4e71c111226591a4eeb5b77efac689ef1dd79a.zip |
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.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala | 22 |
1 files changed, 11 insertions, 11 deletions
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) |