@@ -793,6 +793,8 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
793
793
None
794
794
795
795
abstract class TreeMaker {
796
+ def pos : Position
797
+
796
798
/** captures the scope and the value of the bindings in patterns
797
799
* important *when* the substitution happens (can't accumulate and do at once after the full matcher has been constructed)
798
800
*/
@@ -820,27 +822,33 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
820
822
}
821
823
822
824
case class TrivialTreeMaker (tree : Tree ) extends TreeMaker with NoNewBinders {
825
+ def pos = tree.pos
826
+
823
827
def chainBefore (next : Tree )(casegen : Casegen ): Tree = tree
824
828
}
825
829
826
830
case class BodyTreeMaker (body : Tree , matchPt : Type ) extends TreeMaker with NoNewBinders {
831
+ def pos = body.pos
832
+
827
833
def chainBefore (next : Tree )(casegen : Casegen ): Tree = // assert(next eq EmptyTree)
828
834
atPos(body.pos)(casegen.one(substitution(body))) // since SubstOnly treemakers are dropped, need to do it here
829
835
override def toString = " B" + (body, matchPt)
830
836
}
831
837
832
838
case class SubstOnlyTreeMaker (prevBinder : Symbol , nextBinder : Symbol ) extends TreeMaker {
839
+ val pos = NoPosition
840
+
833
841
val localSubstitution = Substitution (prevBinder, CODE .REF (nextBinder))
834
842
def chainBefore (next : Tree )(casegen : Casegen ): Tree = substitution(next)
835
843
override def toString = " S" + localSubstitution
836
844
}
837
845
838
846
abstract class FunTreeMaker extends TreeMaker {
839
847
val nextBinder : Symbol
848
+ def pos = nextBinder.pos
840
849
}
841
850
842
851
abstract class CondTreeMaker extends FunTreeMaker {
843
- val pos : Position
844
852
val prevBinder : Symbol
845
853
val nextBinderTp : Type
846
854
val cond : Tree
@@ -962,9 +970,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
962
970
- A parameterized type pattern scala.Array[T1], where T1 is a type pattern. // TODO
963
971
This type pattern matches any non-null instance of type scala.Array[U1], where U1 is a type matched by T1.
964
972
**/
965
- case class TypeTestTreeMaker (prevBinder : Symbol , testedBinder : Symbol , expectedTp : Type , nextBinderTp : Type )(_pos : Position , extractorArgTypeTest : Boolean = false ) extends CondTreeMaker {
966
- val pos = _pos
967
-
973
+ case class TypeTestTreeMaker (prevBinder : Symbol , testedBinder : Symbol , expectedTp : Type , nextBinderTp : Type )(override val pos : Position , extractorArgTypeTest : Boolean = false ) extends CondTreeMaker {
968
974
import TypeTestTreeMaker ._
969
975
// println("TTTM"+(prevBinder, extractorArgTypeTest, testedBinder, expectedTp, nextBinderTp))
970
976
@@ -1023,7 +1029,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
1023
1029
}
1024
1030
1025
1031
// need to substitute to deal with existential types -- TODO: deal with existentials better, don't substitute (see RichClass during quick.comp)
1026
- case class EqualityTestTreeMaker (prevBinder : Symbol , patTree : Tree , pos : Position ) extends CondTreeMaker {
1032
+ case class EqualityTestTreeMaker (prevBinder : Symbol , patTree : Tree , override val pos : Position ) extends CondTreeMaker {
1027
1033
val nextBinderTp = prevBinder.info.widen
1028
1034
1029
1035
// NOTE: generate `patTree == patBinder`, since the extractor must be in control of the equals method (also, patBinder may be null)
@@ -1056,6 +1062,8 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
1056
1062
}
1057
1063
1058
1064
case class GuardTreeMaker (guardTree : Tree ) extends TreeMaker with NoNewBinders {
1065
+ val pos = guardTree.pos
1066
+
1059
1067
def chainBefore (next : Tree )(casegen : Casegen ): Tree = casegen.flatMapGuard(substitution(guardTree), next)
1060
1068
override def toString = " G(" + guardTree + " )"
1061
1069
}
@@ -2366,7 +2374,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
2366
2374
object ReusedCondTreeMaker {
2367
2375
def apply (orig : CondTreeMaker ) = new ReusedCondTreeMaker (orig.prevBinder, orig.nextBinder, orig.cond, orig.res, orig.pos)
2368
2376
}
2369
- class ReusedCondTreeMaker (prevBinder : Symbol , val nextBinder : Symbol , cond : Tree , res : Tree , pos : Position ) extends TreeMaker { import CODE ._
2377
+ class ReusedCondTreeMaker (prevBinder : Symbol , val nextBinder : Symbol , cond : Tree , res : Tree , val pos : Position ) extends TreeMaker { import CODE ._
2370
2378
lazy val localSubstitution = Substitution (List (prevBinder), List (CODE .REF (nextBinder)))
2371
2379
lazy val storedCond = freshSym(pos, BooleanClass .tpe, " rc" ) setFlag MUTABLE
2372
2380
lazy val treesToHoist : List [Tree ] = {
@@ -2382,6 +2390,8 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
2382
2390
}
2383
2391
2384
2392
case class ReusingCondTreeMaker (sharedPrefix : List [Test ], toReused : TreeMaker => TreeMaker ) extends TreeMaker { import CODE ._
2393
+ val pos = sharedPrefix.last.treeMaker.pos
2394
+
2385
2395
lazy val localSubstitution = {
2386
2396
// replace binder of each dropped treemaker by corresponding binder bound by the most recent reused treemaker
2387
2397
var mostRecentReusedMaker : ReusedCondTreeMaker = null
0 commit comments