Skip to content

Commit 9fdb1ff

Browse files
committed
Add precision to error message
1 parent 02cbb4b commit 9fdb1ff

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
@@ -609,9 +609,10 @@ trait Checking {
609609
else {
610610
var reportedPt = pt.dropAnnot(defn.UncheckedAnnot)
611611
if (!pat.tpe.isSingleton) reportedPt = reportedPt.widen
612+
val problem = if (pat.tpe <:< pt) "is more specialized" else "does not match"
612613
val fix = if (isPatDef) "`: @unchecked` after" else "`case ` before"
613614
ctx.errorOrMigrationWarning(
614-
ex"""pattern's type ${pat.tpe} is more specialized than the right hand side expression's type $reportedPt
615+
ex"""pattern's type ${pat.tpe} $problem than the right hand side expression's type $reportedPt
615616
|
616617
|If the narrowing is intentional, this can be communicated by writing $fix the full pattern.${err.rewriteNotice}""",
617618
pat.sourcePos)

tests/neg-strict/unchecked-patterns.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ object Test {
77
val 1 *: cs = 1 *: () // error
88

99
val (_: Int | _: Any) = ??? : Any // error
10+
11+
val 1 = 2 // error
1012
}

0 commit comments

Comments
 (0)