-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10395 from som-snytt/backport/refcheck-predef
Avoid printing Predef module as type
- Loading branch information
Showing
14 changed files
with
360 additions
and
15 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
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,15 @@ | ||
i17266.scala:13: warning: synchronized not selected from this instance | ||
synchronized { // error | ||
^ | ||
i17266.scala:26: warning: wait not selected from this instance | ||
wait() // error | ||
^ | ||
i17266.scala:32: warning: notify not selected from this instance | ||
def `maybe notify`(): Unit = notify() | ||
^ | ||
i17266.scala:33: warning: notifyAll not selected from this instance | ||
def `maybe notifyAll`(): Unit = notifyAll() | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
4 warnings | ||
1 error |
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,200 @@ | ||
|
||
// scalac: -Werror -Xsource:3 -Xlint:universal-methods | ||
|
||
// Dotty has top-level defs, so the reference is linted based on context. | ||
// For Scala 2, check result of looking up the identifier. | ||
// Universal members are not imported from root contexts (in particular, Predef). | ||
// Use an explicit import to exercise the warning. | ||
|
||
class Test(val x: Any) extends AnyVal { | ||
import Predef.* | ||
|
||
def test1 = | ||
synchronized { // error | ||
println("hello") | ||
} | ||
|
||
/* correctly errors in Scala 2 | ||
def test2 = | ||
this.synchronized { // not an error (should be?) | ||
println("hello") | ||
} | ||
*/ | ||
|
||
// surprise, ~not~ a universal member | ||
def test16 = | ||
wait() // error | ||
|
||
// OK because Any, so this is kosher | ||
def `maybe hashcode` = hashCode | ||
|
||
// it does know about notify | ||
def `maybe notify`(): Unit = notify() | ||
def `maybe notifyAll`(): Unit = notifyAll() | ||
|
||
} | ||
|
||
// Can't work these tests inside value class. | ||
// | ||
class ObjectHolder { | ||
|
||
object MyLib | ||
|
||
/* ambiguous | ||
def test3 = { | ||
import MyLib.* | ||
synchronized { // error | ||
println("hello") | ||
} | ||
} | ||
*/ | ||
|
||
def test4 = | ||
1.synchronized { // not an error (should be?) | ||
println("hello") | ||
} | ||
|
||
object Test4 { | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
object Test5 { | ||
def test5 = | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
object Test6 { | ||
import MyLib.* | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
object Test7 { | ||
import MyLib.* | ||
def test7 = | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
/* | ||
object Test7b { | ||
def test8 = | ||
import MyLib.* | ||
synchronized { // already an error: Reference to synchronized is ambiguous. | ||
println("hello") | ||
} | ||
} | ||
*/ | ||
|
||
class Test8 { | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
class Test9 { | ||
def test5 = | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
class Test10 { | ||
import MyLib.* | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
class Test11 { | ||
import MyLib.* | ||
def test7 = | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
trait Test12 { | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
trait Test13 { | ||
def test5 = | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
trait Test14 { | ||
import MyLib.* | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
trait Test15 { | ||
import MyLib.* | ||
def test7 = | ||
synchronized { // not an error | ||
println("hello") | ||
} | ||
} | ||
|
||
def test16 = | ||
wait() // error | ||
|
||
def test17 = | ||
this.wait() // not an error (should be?) | ||
|
||
/* ambiguous | ||
def test18 = { | ||
import MyLib.* | ||
wait() // error | ||
} | ||
*/ | ||
|
||
def test19 = | ||
1.wait() // not an error (should be?) | ||
|
||
/* ambiguous | ||
def test20 = | ||
wait(10) // error | ||
*/ | ||
|
||
def test21 = | ||
this.wait(10) // not an error (should be?) | ||
|
||
/* ambiguous | ||
def test22 = { | ||
import MyLib.* | ||
wait(10) // error | ||
} | ||
*/ | ||
|
||
def test23 = | ||
1.wait(10) // not an error (should be?) | ||
|
||
def test24 = | ||
hashCode() // error | ||
|
||
def test25 = | ||
this.hashCode() // not an error (should be?) | ||
|
||
/* ambiguous | ||
def test26 = { | ||
import MyLib.* | ||
hashCode() // error | ||
} | ||
*/ | ||
|
||
def test27 = | ||
1.hashCode()// not an error (should be? probably not) | ||
} |
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,36 @@ | ||
i17266c.scala:7: warning: eq not selected from this instance | ||
def f = eq("hello, world") | ||
^ | ||
i17266c.scala:8: warning: synchronized not selected from this instance | ||
def g = synchronized { println("hello, world") } | ||
^ | ||
i17266c.scala:12: warning: eq not selected from this instance | ||
def f = eq(s) | ||
^ | ||
i17266c.scala:13: warning: synchronized not selected from this instance | ||
def g = synchronized { println(s) } | ||
^ | ||
i17266c.scala:18: warning: eq not selected from this instance | ||
def f = eq(s) | ||
^ | ||
i17266c.scala:19: warning: synchronized not selected from this instance | ||
def g = synchronized { println(s) } | ||
^ | ||
i17266c.scala:7: warning: comparing values of types X.type and String using `eq` will always yield false | ||
def f = eq("hello, world") | ||
^ | ||
i17266c.scala:12: warning: comparing values of types Predef.type and String using `eq` will always yield false | ||
def f = eq(s) | ||
^ | ||
i17266c.scala:18: warning: comparing values of types p.package.type and String using `eq` will always yield false | ||
def f = eq(s) | ||
^ | ||
i17266c.scala:22: warning: comparing values of types X.type and String using `eq` will always yield false | ||
def f = X.eq("hello, world") | ||
^ | ||
i17266c.scala:27: warning: Z and String are unrelated: they will most likely never compare equal | ||
def f = eq("hello, world") | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
11 warnings | ||
1 error |
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 @@ | ||
// scalac: -Werror -Xlint:universal-methods | ||
|
||
object X | ||
|
||
class A(val s: String) extends AnyVal { | ||
import X._ | ||
def f = eq("hello, world") | ||
def g = synchronized { println("hello, world") } | ||
} | ||
class B(val s: String) extends AnyVal { | ||
import Predef._ | ||
def f = eq(s) | ||
def g = synchronized { println(s) } | ||
} | ||
package object p | ||
class C(val s: String) extends AnyVal { | ||
import p.`package`._ | ||
def f = eq(s) | ||
def g = synchronized { println(s) } | ||
} | ||
class Y(val s: String) { | ||
def f = X.eq("hello, world") | ||
def g = X.synchronized { println("hello, world") } | ||
} | ||
class Z(val s: String) { | ||
import X._ | ||
def f = eq("hello, world") | ||
def g = synchronized { println("hello, world") } | ||
} |
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 @@ | ||
t12785.scala:6: warning: comparing values of types Predef.type and Array[B] using `eq` will always yield false | ||
def startsWith[B >: A](that: Array[B]): Boolean = eq(that) | ||
^ | ||
t12785.scala:10: warning: comparing values of types scala.package.type and Array[B] using `eq` will always yield false | ||
eq(that) | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
2 warnings | ||
1 error |
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,14 @@ | ||
// scalac: -Werror | ||
|
||
import scala.Predef._ | ||
|
||
final class ArrayOps[A](private val xs: Array[A]) extends AnyVal { | ||
def startsWith[B >: A](that: Array[B]): Boolean = eq(that) | ||
|
||
def endsWith[B >: A](that: Array[B]): Boolean = { | ||
import scala.`package`._ | ||
eq(that) | ||
} | ||
} | ||
|
||
//warning: comparing values of types type and Array[B] using `eq` will always yield false |
Oops, something went wrong.