File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 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
13201320 case _ =>
13211321 if (tree.name == nme.WILDCARD ) body1
13221322 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/i3200b.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)
13241329 if (ctx.mode.is(Mode .InPatternAlternative ))
13251330 ctx.error(i " Illegal variable ${sym.name} in pattern alternative " , tree.pos)
13261331 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