File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -1210,9 +1210,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
12101210 tpd.cpy.UnApply (body1)(fn, Nil ,
12111211 typed(untpd.Bind (tree.name, untpd.TypedSplice (arg)).withPos(tree.pos), arg.tpe) :: Nil )
12121212 case _ =>
1213- val sym = newPatternBoundSym(tree.name, body1.tpe, tree.pos)
1214- if (ctx.mode.is(Mode .InPatternAlternative )) ctx.error(" Illegal variable in pattern alternative" , tree.pos)
1215- assignType(cpy.Bind (tree)(tree.name, body1), sym)
1213+ if (tree.name == nme.WILDCARD ) body1
1214+ else {
1215+ val sym = newPatternBoundSym(tree.name, body1.tpe, tree.pos)
1216+ if (ctx.mode.is(Mode .InPatternAlternative ))
1217+ ctx.error(i " Illegal variable ${sym.name} in pattern alternative " , tree.pos)
1218+ assignType(cpy.Bind (tree)(tree.name, body1), sym)
1219+ }
12161220 }
12171221 }
12181222
Original file line number Diff line number Diff line change @@ -10,8 +10,12 @@ object Main {
1010
1111// #1612
1212object Test {
13+ case class A ()
1314 def g (p: (Int ,Int )) = p match {
1415 case (10 ,n) | (n,10 ) => println(n) // error // error (Illegal variable in pattern alternative)
1516 case _ => println(" nope" )
1617 }
18+ def test (x : Any ) = x match {
19+ case _ : String | _ @ A () => 1
20+ }
1721}
You can’t perform that action at this time.
0 commit comments