Skip to content

Commit

Permalink
Require postfixOps feature setting
Browse files Browse the repository at this point in the history
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
som-snytt authored and adriaanm committed Aug 31, 2018
1 parent c3f1d57 commit afd25cb
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/library/scala/languageFeature.scala
Expand Up @@ -18,7 +18,7 @@ object languageFeature {
sealed trait dynamics
object dynamics extends dynamics

@meta.languageFeature("postfix operator #", enableRequired = false)
@meta.languageFeature("postfix operator #", enableRequired = true)
sealed trait postfixOps
object postfixOps extends postfixOps

Expand Down
9 changes: 9 additions & 0 deletions test/files/neg/post-postfix.check
@@ -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
6 changes: 6 additions & 0 deletions test/files/neg/post-postfix.scala
@@ -0,0 +1,6 @@

//import language.postfixOps

trait T {
def f(): Int = List(1) head
}
10 changes: 4 additions & 6 deletions test/files/neg/t5675.scala
@@ -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
}
30 changes: 15 additions & 15 deletions test/files/neg/t6120.check
@@ -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
29 changes: 26 additions & 3 deletions test/files/neg/t6120.scala
@@ -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
*/
7 changes: 7 additions & 0 deletions test/files/pos/post-postfix.scala
@@ -0,0 +1,7 @@

// required
import language.postfixOps

trait T {
def f(): Int = List(1) head
}
6 changes: 3 additions & 3 deletions test/files/pos/t8223.scala
Expand Up @@ -17,9 +17,9 @@ package object p {
type EnvAlias[W <: HasA] = ViewEnv[W#A]
type SubAlias[W <: HasA] = ViewEnv[W#A]#SubView

def f0[R](xs: R)(implicit tc: Indexable[R]): ViewEnv[tc.A]#SubView = new ViewEnv[tc.A]() get
def f1[R](xs: R)(implicit tc: Indexable[R]): EnvAlias[tc.type]#SubView = new ViewEnv[tc.A]() get
def f2[R](xs: R)(implicit tc: Indexable[R]): SubAlias[tc.type] = new ViewEnv[tc.A]() get
def f0[R](xs: R)(implicit tc: Indexable[R]): ViewEnv[tc.A]#SubView = new ViewEnv[tc.A]().get
def f1[R](xs: R)(implicit tc: Indexable[R]): EnvAlias[tc.type]#SubView = new ViewEnv[tc.A]().get
def f2[R](xs: R)(implicit tc: Indexable[R]): SubAlias[tc.type] = new ViewEnv[tc.A]().get

def g0 = f0(Array(1)) has 2 // ok
def g1 = f1(Array(1)) has 2 // ok
Expand Down
2 changes: 1 addition & 1 deletion test/files/pos/tcpoly_infer_explicit_tuple_wrapper.scala
Expand Up @@ -9,5 +9,5 @@ object Test {

val t = (List(1, 2, 3), List(6, 5, 4))

tupleOfIterableWrapper(t) unzip
tupleOfIterableWrapper(t).unzip
}
4 changes: 2 additions & 2 deletions test/files/pos/tcpoly_infer_implicit_tuple_wrapper.scala
Expand Up @@ -11,7 +11,7 @@ object Test {

val t = (List(1, 2, 3), List(6, 5, 4))

tupleOfIterableWrapper(t) unzip
tupleOfIterableWrapper(t).unzip

t unzip
t.unzip
}
2 changes: 1 addition & 1 deletion test/files/pos/tcpoly_infer_ticket716.scala
Expand Up @@ -21,6 +21,6 @@ object Functor{
object GeneralLiftingDemo extends App {
import Functor._
val l = List(1,2,3)
val res = l fmap( 1+) // TODO: should not need explicit call to lifttoOO
val res = l fmap (1 + _) // TODO: should not need explicit call to lifttoOO
println("OO : " + res )
}

0 comments on commit afd25cb

Please sign in to comment.