From 802771b403f6dd0f09e01e4e3e1189c70d4b7bec Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 8 Aug 2012 05:29:43 -0700 Subject: Better pattern matcher error message. For the common case when someone hasn't quite grokked the significance of lower case in a pattern match. I'd like to make all the unreachables errors, not warnings, but there may be a bug or two to clear out first. class A { def badEquals(x: Any, y: Any) = x match { case y => true case _ => false } } a.scala:3: warning: patterns after a variable pattern cannot match (SLS 8.1.1) If you intended to match against parameter y of method badEquals, you must use backticks, like: case `y` => case y => true ^ a.scala:4: warning: unreachable code due to variable pattern 'y' on line 3 case _ => false ^ two warnings found --- test/files/neg/newpat_unreachable.check | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/files/neg/newpat_unreachable.check (limited to 'test/files/neg/newpat_unreachable.check') diff --git a/test/files/neg/newpat_unreachable.check b/test/files/neg/newpat_unreachable.check new file mode 100644 index 0000000000..08453cac19 --- /dev/null +++ b/test/files/neg/newpat_unreachable.check @@ -0,0 +1,27 @@ +newpat_unreachable.scala:6: error: patterns after a variable pattern cannot match (SLS 8.1.1) +If you intended to match against parameter b of method contrivedExample, you must use backticks, like: case `b` => + case b => println("matched b") + ^ +newpat_unreachable.scala:7: error: unreachable code due to variable pattern 'b' on line 6 +If you intended to match against parameter c of method contrivedExample, you must use backticks, like: case `c` => + case c => println("matched c") + ^ +newpat_unreachable.scala:8: error: unreachable code due to variable pattern 'b' on line 6 +If you intended to match against value d in class A, you must use backticks, like: case `d` => + case d => println("matched d") + ^ +newpat_unreachable.scala:9: error: unreachable code due to variable pattern 'b' on line 6 + case _ => println("matched neither") + ^ +newpat_unreachable.scala:22: error: patterns after a variable pattern cannot match (SLS 8.1.1) +If you intended to match against parameter b of method g, you must use backticks, like: case `b` => + case b => 1 + ^ +newpat_unreachable.scala:23: error: unreachable code due to variable pattern 'b' on line 22 +If you intended to match against parameter c of method h, you must use backticks, like: case `c` => + case c => 2 + ^ +newpat_unreachable.scala:24: error: unreachable code due to variable pattern 'b' on line 22 + case _ => 3 + ^ +7 errors found -- cgit v1.2.3