-
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.
- Loading branch information
Showing
3 changed files
with
49 additions
and
4 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,14 @@ | ||
-- [E194] Potential Issue Warning: tests/warn/i22267.scala:13:26 ------------------------------------------------------- | ||
13 | extension (self: C) def m(n: Double): Unit = println(2->n) // warn | ||
| ^ | ||
| Extension method m will never be selected from type C | ||
| because C already has a member with the same name and compatible parameter types. | ||
|-------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| Although extensions can be overloaded, they do not overload existing member methods. | ||
| An extension method can be invoked as a regular method, but if that is the intended usage, | ||
| it should not be defined as an extension. | ||
| | ||
| The extension may be invoked as though selected from an arbitrary type if conversions are in play. | ||
-------------------------------------------------------------------------------------------------------------------- |
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,28 @@ | ||
//> using options -explain | ||
|
||
import language.implicitConversions | ||
|
||
case class M[T](value: T) | ||
given [T]: Conversion[M[T], T] = _.value | ||
class C: | ||
def m(n: Double): Unit = println(0->n) | ||
object C: | ||
given Ops = Ops() | ||
class Ops: | ||
extension (self: C) def m(n: Int): Unit = println(1->n) | ||
extension (self: C) def m(n: Double): Unit = println(2->n) // warn | ||
extension (self: C) def m(s: String): Unit = println(3->s) | ||
|
||
@main def test() = | ||
val c = M(C()) | ||
def i = 42 | ||
def pi = 3.14 | ||
c.value.m(i) | ||
c.value.m(pi) | ||
c.m(i) // conversion | ||
c.m(pi) // conversion | ||
c.m("hello, world") // extension | ||
//m(c)(pi) | ||
val c0 = C() | ||
c0.m(pi) | ||
c0.m("hello, world") |