Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
10 changed files
with
155 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Impls_1.scala:5: error: macro implementations cannot have implicit parameters other than AbsTypeTag evidences | ||
def foo[U: c.AbsTypeTag: Numeric](c: Ctx) = { | ||
^ | ||
one error found | ||
Impls_1.scala:5: error: macro implementations cannot have implicit parameters other than AbsTypeTag evidences | ||
def foo[U: c.AbsTypeTag: Numeric](c: Ctx) = { | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Impls_Macros_1.scala:5: error: macro implementations cannot have implicit parameters other than AbsTypeTag evidences | ||
def foo_targs[T, U: c.AbsTypeTag](c: Ctx)(implicit x: c.Expr[Int]) = { | ||
^ | ||
one error found | ||
Impls_Macros_1.scala:5: error: macro implementations cannot have implicit parameters other than AbsTypeTag evidences | ||
def foo_targs[T, U: c.AbsTypeTag](c: Ctx)(implicit x: c.Expr[Int]) = { | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Xfatal-warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
object Test { | ||
class A { | ||
val d = 55 | ||
|
||
def contrivedExample[A, B, C](a: A, b: B, c: C): Unit = a match { | ||
case b => println("matched b") | ||
case c => println("matched c") | ||
case d => println("matched d") | ||
case _ => println("matched neither") | ||
} | ||
|
||
def correctExample[A, B, C](a: A, b: B, c: C): Unit = a match { | ||
case `b` => println("matched b") | ||
case `c` => println("matched c") | ||
case `d` => println("matched d") | ||
case _ => println("matched neither") | ||
} | ||
|
||
def f[A](a: A) = { | ||
def g[B](b: B) = { | ||
def h[C](c: C) = a match { | ||
case b => 1 | ||
case c => 2 | ||
case _ => 3 | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters