Skip to content

Commit 47256d2

Browse files
committed
Add Eq check for Apply tree in adapting patterns
1 parent 96afef1 commit 47256d2

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ class Typer extends Namer
24532453
*/
24542454
protected def checkEqualityEvidence(tree: tpd.Tree, pt: Type)(implicit ctx: Context) : Unit = {
24552455
tree match {
2456-
case _: RefTree | _: Literal
2456+
case _: RefTree | _: Literal | _: Apply
24572457
if !isVarPattern(tree) &&
24582458
!(tree.tpe <:< pt) (ctx.addMode(Mode.GADTflexible)) =>
24592459
val cmp =

tests/neg/i1846.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
val x = 42
4+
val Y = "h"
5+
6+
x match { case { 42 } => 42 } // ok
7+
x match { case { 42.toString } => 42 } // error
8+
x match { case { 42 }.toString => 42 } // error
9+
x match { case { "h" }.toString => println(42) } // error
10+
x match { case { "h".toString } => println(42) } // error
11+
x match { case Y => println(42) } // error
12+
x match { case Y.toString => println(42) } // error
13+
14+
Y match { case Y.toString => println(42) } // ok
15+
Y match { case { Y.toString } => println(42) } // ok
16+
Y match { case { Y }.toString => println(42) } // ok
17+
}
18+
}

tests/run/i1846.check

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/run/i1846.scala

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)