Skip to content

Commit 82b1eb8

Browse files
committed
Add precision to error message
1 parent c2a41b6 commit 82b1eb8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,10 @@ trait Checking {
607607
def fail(pat: Tree, pt: Type): Boolean = {
608608
var reportedPt = pt.dropAnnot(defn.UncheckedAnnot)
609609
if (!pat.tpe.isSingleton) reportedPt = reportedPt.widen
610+
val problem = if (pat.tpe <:< pt) "is more specialized" else "does not match"
610611
val fix = if (isPatDef) "`: @unchecked` after" else "`case ` before"
611612
ctx.errorOrMigrationWarning(
612-
ex"""pattern's type ${pat.tpe} is more specialized than the right hand side expression's type $reportedPt
613+
ex"""pattern's type ${pat.tpe} $problem than the right hand side expression's type $reportedPt
613614
|
614615
|If the narrowing is intentional, this can be communicated by writing $fix the full pattern.${err.rewriteNotice}""",
615616
pat.sourcePos)

tests/neg-strict/unchecked-patterns.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ object Test {
99

1010
val (_: Int | _: Any) = ??? : Any // error
1111

12+
val 1 = 2 // error
13+
1214
object Positive { def unapply(i: Int): Option[Int] = Some(i).filter(_ > 0) }
1315
object Always1 { def unapply(i: Int): Some[Int] = Some(i) }
1416
object Pair { def unapply(t: (Int, Int)): t.type = t }

0 commit comments

Comments
 (0)