-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn if extension is hidden by member of receiver
- Loading branch information
Showing
13 changed files
with
203 additions
and
34 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ package tests | |
package inheritedMembers1 | ||
|
||
|
||
/*<-*/@annotation.nowarn/*->*/ | ||
class A | ||
{ | ||
def A: String | ||
|
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,60 @@ | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:26:6 ----------------------------------------------------------- | ||
26 | def t = 27 // error | ||
| ^ | ||
| Suspicious extension t is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:28:6 ----------------------------------------------------------- | ||
28 | def g(x: String)(i: Int): String = x*i // error | ||
| ^ | ||
| Suspicious extension g is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:29:6 ----------------------------------------------------------- | ||
29 | def h(x: String): String = x // error | ||
| ^ | ||
| Suspicious extension h is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:31:6 ----------------------------------------------------------- | ||
31 | def j(x: Any, y: Int): String = (x.toString)*y // error | ||
| ^ | ||
| Suspicious extension j is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:32:6 ----------------------------------------------------------- | ||
32 | def k(x: String): String = x // error | ||
| ^ | ||
| Suspicious extension k is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:33:6 ----------------------------------------------------------- | ||
33 | def l(using String): String = summon[String] // error: can't be called implicitly | ||
| ^ | ||
| Suspicious extension l is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:34:6 ----------------------------------------------------------- | ||
34 | def m(using String): String = "m" + summon[String] // error | ||
| ^ | ||
| Suspicious extension m is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:35:6 ----------------------------------------------------------- | ||
35 | def n(using String): String = "n" + summon[String] // error | ||
| ^ | ||
| Suspicious extension n is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:36:6 ----------------------------------------------------------- | ||
36 | def o: String = "42" // error | ||
| ^ | ||
| Suspicious extension o is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E193] Potential Issue Error: tests/neg/i16743.scala:37:6 ----------------------------------------------------------- | ||
37 | def u: Int = 27 // error | ||
| ^ | ||
| Suspicious extension u is already a member of T | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,70 @@ | ||
|
||
//> using options -Werror | ||
|
||
trait G | ||
given G = new G { override def toString = "mygiven" } | ||
given String = "aGivenString" | ||
|
||
trait T: | ||
def t = 42 | ||
def f(x: String): String = x*2 | ||
def g(x: String)(y: String): String = (x+y)*2 | ||
def h(x: Any): String = x.toString*2 | ||
def i(x: Any, y: String): String = (x.toString+y)*2 | ||
def j(x: Any, y: Any): String = (x.toString+y.toString) | ||
def k(using G): String = summon[G].toString | ||
def l(using G): String = summon[G].toString | ||
def m: String = "mystring" | ||
def n: Result = Result() | ||
def o: Int = 42 | ||
def u: Int = 42 | ||
def u(n: Int): Int = u + n | ||
def v(n: Int): Int = u + n | ||
def v(s: String): String = s + u | ||
|
||
extension (_t: T) | ||
def t = 27 // error | ||
def f(i: Int): String = String.valueOf(i) | ||
def g(x: String)(i: Int): String = x*i // error | ||
def h(x: String): String = x // error | ||
def i(x: Any, y: Int): String = (x.toString)*y | ||
def j(x: Any, y: Int): String = (x.toString)*y // error | ||
def k(x: String): String = x // error | ||
def l(using String): String = summon[String] // error: can't be called implicitly | ||
def m(using String): String = "m" + summon[String] // error | ||
def n(using String): String = "n" + summon[String] // error | ||
def o: String = "42" // error | ||
def u: Int = 27 // error | ||
def v(d: Double) = 3.14 | ||
|
||
// deferred extension is defined in subclass | ||
trait Foo: | ||
type X | ||
extension (x: X) def t: Int | ||
|
||
trait Bar extends Foo: | ||
type X = T | ||
extension (x: X) def t = x.t | ||
|
||
// extension on opaque type matches member of underlying type | ||
opaque type IArray[+T] = Array[? <: T] | ||
object IArray: | ||
extension (arr: IArray[Byte]) def length: Int = arr.asInstanceOf[Array[Byte]].length | ||
|
||
class Result: | ||
def apply(using String): String = s"result ${summon[String]}" | ||
|
||
@main def test() = | ||
val x = new T {} | ||
println(x.f(42)) // OK! | ||
//println(x.g("x")(42)) // NOT OK! | ||
println(x.h("hi")) // member! | ||
println(x.i("hi", 5)) // OK! | ||
println(x.j("hi", 5)) // member! | ||
println(x.k) | ||
println(x.l(using "x")) | ||
println(x.l) | ||
println(x.m(using "x")) | ||
println(x.m(2)) | ||
println(x.n) // OK just checks | ||
println(x.n(using "x")) // also just checks |
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