Skip to content

Commit dd03912

Browse files
authored
Merge pull request #4237 from dotty-staging/fix-4198
Fix #4198: correctly enter pattern symbols in TreeChecker
2 parents 1fdb94b + 352f716 commit dd03912

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,19 @@ class TreeChecker extends Phase with SymTransformer {
177177
res
178178
}
179179

180+
def withPatSyms[T](syms: List[Symbol])(op: => T)(implicit ctx: Context) = {
181+
nowDefinedSyms ++= syms
182+
val res = op
183+
nowDefinedSyms --= syms
184+
res
185+
}
186+
180187
def assertDefined(tree: untpd.Tree)(implicit ctx: Context) =
181188
if (
182189
tree.symbol.maybeOwner.isTerm &&
183190
!(tree.symbol.is(Label) && !tree.symbol.owner.isClass && ctx.phase.labelsReordered) // labeldefs breaks scoping
184191
)
185-
assert(nowDefinedSyms contains tree.symbol, i"undefined symbol ${tree.symbol}")
192+
assert(nowDefinedSyms contains tree.symbol, i"undefined symbol ${tree.symbol} at line " + tree.pos.line)
186193

187194
/** assert Java classes are not used as objects */
188195
def assertIdentNotJavaClass(tree: Tree)(implicit ctx: Context): Unit = tree match {
@@ -400,7 +407,7 @@ class TreeChecker extends Phase with SymTransformer {
400407
}
401408

402409
override def typedCase(tree: untpd.CaseDef, pt: Type, selType: Type, gadtSyms: Set[Symbol])(implicit ctx: Context): CaseDef = {
403-
withDefinedSyms(tree.pat.asInstanceOf[tpd.Tree].filterSubTrees(_.isInstanceOf[ast.Trees.Bind[_]])) {
410+
withPatSyms(tpd.patVars(tree.pat.asInstanceOf[tpd.Tree])) {
404411
super.typedCase(tree, pt, selType, gadtSyms)
405412
}
406413
}

tests/pos/i4198.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Foo {
2+
def foo(x: Any): Unit = {
3+
x match {
4+
case y: Bar[_] =>
5+
y.value match {
6+
case value: Bar[_] => // here x is an instance of Bar[Bar[_]]
7+
case _ =>
8+
}
9+
}
10+
}
11+
}
12+
13+
class Bar[T] {
14+
def value: T = ???
15+
}

0 commit comments

Comments
 (0)