Skip to content

Commit 66220c9

Browse files
author
Adriaan Moors
committed
all treemakers need positions for unreachable error
1 parent 71006c0 commit 66220c9

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,8 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
793793
None
794794

795795
abstract class TreeMaker {
796+
def pos: Position
797+
796798
/** captures the scope and the value of the bindings in patterns
797799
* important *when* the substitution happens (can't accumulate and do at once after the full matcher has been constructed)
798800
*/
@@ -820,27 +822,33 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
820822
}
821823

822824
case class TrivialTreeMaker(tree: Tree) extends TreeMaker with NoNewBinders {
825+
def pos = tree.pos
826+
823827
def chainBefore(next: Tree)(casegen: Casegen): Tree = tree
824828
}
825829

826830
case class BodyTreeMaker(body: Tree, matchPt: Type) extends TreeMaker with NoNewBinders {
831+
def pos = body.pos
832+
827833
def chainBefore(next: Tree)(casegen: Casegen): Tree = // assert(next eq EmptyTree)
828834
atPos(body.pos)(casegen.one(substitution(body))) // since SubstOnly treemakers are dropped, need to do it here
829835
override def toString = "B"+(body, matchPt)
830836
}
831837

832838
case class SubstOnlyTreeMaker(prevBinder: Symbol, nextBinder: Symbol) extends TreeMaker {
839+
val pos = NoPosition
840+
833841
val localSubstitution = Substitution(prevBinder, CODE.REF(nextBinder))
834842
def chainBefore(next: Tree)(casegen: Casegen): Tree = substitution(next)
835843
override def toString = "S"+ localSubstitution
836844
}
837845

838846
abstract class FunTreeMaker extends TreeMaker {
839847
val nextBinder: Symbol
848+
def pos = nextBinder.pos
840849
}
841850

842851
abstract class CondTreeMaker extends FunTreeMaker {
843-
val pos: Position
844852
val prevBinder: Symbol
845853
val nextBinderTp: Type
846854
val cond: Tree
@@ -962,9 +970,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
962970
- A parameterized type pattern scala.Array[T1], where T1 is a type pattern. // TODO
963971
This type pattern matches any non-null instance of type scala.Array[U1], where U1 is a type matched by T1.
964972
**/
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 {
968974
import TypeTestTreeMaker._
969975
// println("TTTM"+(prevBinder, extractorArgTypeTest, testedBinder, expectedTp, nextBinderTp))
970976

@@ -1023,7 +1029,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
10231029
}
10241030

10251031
// 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 {
10271033
val nextBinderTp = prevBinder.info.widen
10281034

10291035
// 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
10561062
}
10571063

10581064
case class GuardTreeMaker(guardTree: Tree) extends TreeMaker with NoNewBinders {
1065+
val pos = guardTree.pos
1066+
10591067
def chainBefore(next: Tree)(casegen: Casegen): Tree = casegen.flatMapGuard(substitution(guardTree), next)
10601068
override def toString = "G("+ guardTree +")"
10611069
}
@@ -2366,7 +2374,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
23662374
object ReusedCondTreeMaker {
23672375
def apply(orig: CondTreeMaker) = new ReusedCondTreeMaker(orig.prevBinder, orig.nextBinder, orig.cond, orig.res, orig.pos)
23682376
}
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._
23702378
lazy val localSubstitution = Substitution(List(prevBinder), List(CODE.REF(nextBinder)))
23712379
lazy val storedCond = freshSym(pos, BooleanClass.tpe, "rc") setFlag MUTABLE
23722380
lazy val treesToHoist: List[Tree] = {
@@ -2382,6 +2390,8 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
23822390
}
23832391

23842392
case class ReusingCondTreeMaker(sharedPrefix: List[Test], toReused: TreeMaker => TreeMaker) extends TreeMaker { import CODE._
2393+
val pos = sharedPrefix.last.treeMaker.pos
2394+
23852395
lazy val localSubstitution = {
23862396
// replace binder of each dropped treemaker by corresponding binder bound by the most recent reused treemaker
23872397
var mostRecentReusedMaker: ReusedCondTreeMaker = null

0 commit comments

Comments
 (0)