Skip to content

Commit 7c8b636

Browse files
committed
Limit bad advice given for erroneous pattern.
Don't suggest "_: <none>" as an alternative when the pattern type doesn't conform to the expected type.
1 parent 09058cf commit 7c8b636

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ trait TypeDiagnostics {
285285
case xs => xs map (_ => "_") mkString (clazz.name + "[", ",", "]")
286286
})+ "`"
287287

288-
"\nNote: if you intended to match against the class, try "+ caseString
289-
288+
if (!clazz.exists) ""
289+
else "\nNote: if you intended to match against the class, try "+ caseString
290290
}
291291

292292
case class TypeDiag(tp: Type, sym: Symbol) extends Ordered[TypeDiag] {

test/files/neg/bad-advice.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bad-advice.scala:4: error: pattern type is incompatible with expected type;
2+
found : Bip.type
3+
required: Int
4+
case Bip => true
5+
^
6+
one error found

test/files/neg/bad-advice.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xfatal-warnings

test/files/neg/bad-advice.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Bip
2+
object Test {
3+
def f(x: Int) = x match {
4+
case Bip => true
5+
}
6+
}

0 commit comments

Comments
 (0)