Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit turns the feature warning into an error if `postfixOps` is not enabled. Popular sentiment has turned against the feature, and requiring enablement raises the barrier to entry. In particular, beginners will not stumble across it accidentally.
- Loading branch information
Showing
11 changed files
with
75 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
post-postfix.scala:5: error: postfix operator head needs to be enabled | ||
by making the implicit value scala.language.postfixOps visible. | ||
This can be achieved by adding the import clause 'import scala.language.postfixOps' | ||
or by setting the compiler option -language:postfixOps. | ||
See the Scaladoc for value scala.language.postfixOps for a discussion | ||
why the feature needs to be explicitly enabled. | ||
def f(): Int = List(1) head | ||
^ | ||
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,6 @@ | ||
|
||
//import language.postfixOps | ||
|
||
trait T { | ||
def f(): Int = List(1) head | ||
} |
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,9 +1,7 @@ | ||
// scalac: -Xfatal-warnings | ||
// | ||
class PostFix { | ||
val list = List(1, 2, 3) | ||
def main(args: Array[String]): Unit = { | ||
val a = list filter (2 !=) | ||
val b = list filter (2 != _) | ||
} | ||
// without -feature, don't double-count the warning | ||
// | ||
class OneWarningOnly { | ||
implicit def `this is why we warn`(x: Any): Int = x.toString.toInt | ||
} |
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,20 +1,20 @@ | ||
t6120.scala:7: warning: postfix operator bippy should be enabled | ||
by making the implicit value scala.language.postfixOps visible. | ||
This can be achieved by adding the import clause 'import scala.language.postfixOps' | ||
or by setting the compiler option -language:postfixOps. | ||
See the Scaladoc for value scala.language.postfixOps for a discussion | ||
why the feature should be explicitly enabled. | ||
def f = null == null bippy | ||
^ | ||
t6120.scala:7: warning: method bippy in class BooleanOps is deprecated (since 2.11.0): bobo | ||
def f = null == null bippy | ||
^ | ||
t6120.scala:7: warning: comparing values of types Null and Null using `==' will always yield true | ||
def f = null == null bippy | ||
t6120.scala:14: warning: method bippy in class BooleanOps is deprecated (since 2.11.0): bobo | ||
def f = (null == null).bippy | ||
^ | ||
t6120.scala:14: warning: method bippy in class BooleanOps has changed semantics in version 2.12.6: | ||
Used to return 5 | ||
def f = (null == null).bippy | ||
^ | ||
t6120.scala:14: warning: comparing values of types Null and Null using `==' will always yield true | ||
def f = (null == null).bippy | ||
^ | ||
t6120.scala:15: warning: method bippy in class BooleanOps is deprecated (since 2.11.0): bobo | ||
def g = true.bippy | ||
^ | ||
t6120.scala:8: warning: method bippy in class BooleanOps is deprecated (since 2.11.0): bobo | ||
t6120.scala:15: warning: method bippy in class BooleanOps has changed semantics in version 2.12.6: | ||
Used to return 5 | ||
def g = true.bippy | ||
^ | ||
error: No warnings can be incurred under -Xfatal-warnings. | ||
four warnings found | ||
5 warnings found | ||
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,9 +1,32 @@ | ||
// scalac: -feature -deprecation -Xfatal-warnings | ||
// scalac: -deprecation -Xmigration:2.10 -Xfatal-warnings | ||
// | ||
// showing that multiple warnings at same location are reported | ||
// | ||
package scala.test | ||
import scala.annotation._ | ||
|
||
class A { | ||
implicit class BooleanOps(val b: Boolean) { | ||
@deprecated("bobo", "2.11.0") def bippy() = 5 | ||
@deprecated("bobo", since="2.11.0") | ||
@migration("Used to return 5", changedIn="2.12.6") | ||
def bippy() = 42 | ||
} | ||
def f = null == null bippy | ||
def f = (null == null).bippy | ||
def g = true.bippy | ||
} | ||
|
||
/* | ||
$ ~/scala-2.10.4/bin/scalac -d /tmp -Xmigration:2.10 -deprecation test/files/neg/t6120.scala | ||
test/files/neg/t6120.scala:14: warning: method bippy in class BooleanOps is deprecated: bobo | ||
def f = (null == null).bippy | ||
^ | ||
test/files/neg/t6120.scala:14: warning: comparing values of types Null and Null using `==' will always yield true | ||
def f = (null == null).bippy | ||
^ | ||
test/files/neg/t6120.scala:15: warning: method bippy in class BooleanOps is deprecated: bobo | ||
def g = true.bippy | ||
^ | ||
three warnings 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,7 @@ | ||
|
||
// required | ||
import language.postfixOps | ||
|
||
trait T { | ||
def f(): Int = List(1) head | ||
} |
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
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