From b3d9dfa9857aeb937a987536b3e2029d3be0030b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 18 Aug 2013 15:14:47 -0700 Subject: An unapplySeq-via-String test. There are a lot of details yet to be ironed out when it comes to sequences, but at least here's a little evidence that the basic mechanisms work. --- .../scala/tools/nsc/transform/patmat/MatchCodeGen.scala | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (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 2bd14d923a..8de8eb7d92 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala @@ -65,7 +65,18 @@ trait MatchCodeGen extends Interface { def fun(arg: Symbol, body: Tree): Tree = Function(List(ValDef(arg)), body) 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)) - def drop(tgt: Tree)(n: Int): Tree = gen.mkMethodCall(traversableDropMethod, tgt :: LIT(n) :: Nil) + + 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) + ) // 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