File tree 2 files changed +23
-2
lines changed
compiler/src/dotty/tools/dotc/typer 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -1344,11 +1344,12 @@ class Typer extends Namer
1344
1344
case _ =>
1345
1345
if (tree.name == nme.WILDCARD ) body1
1346
1346
else {
1347
- // for a singleton pattern like `x @ Nil`, `x` should get the type from the scrutinee
1347
+ // For a pattern like `x @ P`, x gets the type of the scrutinee and pattern.
1348
+ // For a singleton pattern like `x @ Nil`, `x` should get the type from the scrutinee
1348
1349
// see tests/neg/i3200b.scala and SI-1503
1349
1350
val symTp =
1350
1351
if (body1.tpe.isInstanceOf [TermRef ]) pt1
1351
- else body1.tpe.underlyingIfRepeated(isJava = false )
1352
+ else AndType .make( body1.tpe.underlyingIfRepeated(isJava = false ), pt1 )
1352
1353
val sym = ctx.newPatternBoundSymbol(tree.name, symTp, tree.pos)
1353
1354
if (pt == defn.ImplicitScrutineeTypeRef ) sym.setFlag(Implicit )
1354
1355
if (ctx.mode.is(Mode .InPatternAlternative ))
Original file line number Diff line number Diff line change
1
+ trait X
2
+ trait Y
3
+
4
+ trait MyError
5
+
6
+ class Test {
7
+ def test (xs : List [X ]): List [X ] = xs.collect { case y : Y => y }
8
+
9
+ def test2 (x : X ) = x match {
10
+ case y : Y =>
11
+ val b : X = y
12
+ }
13
+
14
+ def test3 =
15
+ try ???
16
+ catch {
17
+ case e : MyError =>
18
+ throw e
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments