Skip to content

Commit d340a4d

Browse files
committed
Add Eq check for Apply tree in adapting patterns
1 parent cff918e commit d340a4d

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
@@ -2437,7 +2437,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
24372437
*/
24382438
protected def checkEqualityEvidence(tree: tpd.Tree, pt: Type)(implicit ctx: Context) : Unit = {
24392439
tree match {
2440-
case _: RefTree | _: Literal
2440+
case _: RefTree | _: Literal | _: Apply
24412441
if !isVarPattern(tree) &&
24422442
!(tree.tpe <:< pt) (ctx.addMode(Mode.GADTflexible)) =>
24432443
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)