File tree 3 files changed +17
-1
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -1320,7 +1320,12 @@ class Typer extends Namer
1320
1320
case _ =>
1321
1321
if (tree.name == nme.WILDCARD ) body1
1322
1322
else {
1323
- val sym = ctx.newPatternBoundSymbol(tree.name, body1.tpe.underlyingIfRepeated(isJava = false ), tree.pos)
1323
+ // for a singleton pattern like `x @ Nil`, `x` should get the type from the scrutinee
1324
+ // see tests/neg/3200b.scala and SI-1503
1325
+ val symTp =
1326
+ if (body1.tpe.isInstanceOf [TermRef ]) pt1
1327
+ else body1.tpe.underlyingIfRepeated(isJava = false )
1328
+ val sym = ctx.newPatternBoundSymbol(tree.name, symTp, tree.pos)
1324
1329
if (ctx.mode.is(Mode .InPatternAlternative ))
1325
1330
ctx.error(i " Illegal variable ${sym.name} in pattern alternative " , tree.pos)
1326
1331
assignType(cpy.Bind (tree)(tree.name, body1), sym)
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ case object Bob { override def equals (other : Any ) = true }
3
+ def main (args : Array [String ]): Unit = {
4
+ val m : Bob .type = (5 : Any ) match { case x @ Bob => x } // error
5
+ }
6
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ def main (args : Array [String ]): Unit = {
3
+ val a : Nil .type = (Vector (): Any ) match { case n @ Nil => n } // error
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments