-
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
1 parent
132001e
commit 27f4e30
Showing
2 changed files
with
173 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import language.experimental.relaxedExtensionImports | ||
|
||
import scala.annotation.targetName | ||
trait Foo[+T] | ||
|
||
def foo[T](t: T): Foo[T] = new Foo[T] {} | ||
|
||
object One: | ||
extension (s: Foo[String]) | ||
def wow: Unit = println(s) | ||
|
||
object Two: | ||
extension (i: Foo[Int]) | ||
def wow: Unit = println(i) | ||
|
||
object Three: | ||
extension (s: Foo[String]) | ||
@targetName("wowString") | ||
def wow: Unit = println(s) | ||
extension (i: Foo[Int]) | ||
@targetName("wowInt") | ||
def wow: Unit = println(i) | ||
|
||
object Four: | ||
implicit class WowString(s: Foo[String]): | ||
def wow: Unit = println(s) | ||
|
||
object Five: | ||
implicit class WowInt(i: Foo[Int]): | ||
def wow: Unit = println(i) | ||
|
||
object Compiles: | ||
import Three._ | ||
def test: Unit = | ||
foo(5).wow | ||
foo("five").wow | ||
|
||
object AlsoCompiles: | ||
import Four._ | ||
import Five._ | ||
def test: Unit = | ||
foo(5).wow | ||
foo("five").wow | ||
|
||
object UsedToFail: | ||
import One._ | ||
import Compiles.* | ||
import Two._ | ||
def test: Unit = | ||
foo(5).wow | ||
foo("five").wow | ||
|
||
object Conflicting: | ||
extension (i: Foo[Int]) | ||
def wow: Unit = println(i) | ||
|
||
object Named: | ||
import One.wow | ||
import Two.wow | ||
import Conflicting._ | ||
def test: Unit = | ||
foo(5).wow // ok | ||
foo("five").wow // ok | ||
|
||
object Named2: | ||
import Conflicting._ | ||
import One.wow | ||
import Two.wow | ||
def test: Unit = | ||
foo(5).wow // ok | ||
foo("five").wow // ok | ||
|
||
val Alias = Two | ||
|
||
object Named3: | ||
import Alias._ | ||
import Two._ | ||
def test: Unit = | ||
foo(5).wow // ok | ||
|
||
object Named4: | ||
import Two._ | ||
import Alias._ | ||
def test: Unit = | ||
foo(5).wow // ok |
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,88 @@ | ||
import language.experimental.relaxedExtensionImports | ||
// evolve tests/pos/i16920.scala to abstract out Wow to a typeclass, more like the typical library use case | ||
|
||
trait Wow[T]: | ||
extension (t: T) | ||
def wow: Unit | ||
|
||
object One: | ||
given wowStr: Wow[String] with | ||
extension (s: String) | ||
def wow: Unit = println(s) | ||
|
||
object Two: | ||
given wowInt: Wow[Int] with | ||
extension (i: Int) | ||
def wow: Unit = println(i) | ||
|
||
object Three: | ||
given wowStr: Wow[String] with | ||
extension (s: String) | ||
def wow: Unit = println(s) | ||
given wowInt: Wow[Int] with | ||
extension (i: Int) | ||
def wow: Unit = println(i) | ||
|
||
object Four: | ||
implicit class WowString(s: String): | ||
def wow: Unit = println(s) | ||
|
||
object Five: | ||
implicit class WowInt(i: Int): | ||
def wow: Unit = println(i) | ||
|
||
object Compiles: | ||
import Three.given | ||
def test: Unit = | ||
5.wow | ||
"five".wow | ||
|
||
object AlsoCompiles: | ||
import Four.given | ||
import Five.given | ||
def test: Unit = | ||
5.wow | ||
"five".wow | ||
|
||
object UsedToFail: | ||
import One.given | ||
import Compiles.* | ||
import Two.given | ||
def test: Unit = | ||
5.wow | ||
"five".wow | ||
|
||
object Conflicting: | ||
given wowInt: Wow[Int] with | ||
extension (i: Int) | ||
def wow: Unit = println(i) | ||
|
||
object Named: | ||
import One.wowStr | ||
import Two.wowInt | ||
import Conflicting.given | ||
def test: Unit = | ||
5.wow // ok | ||
"five".wow // ok | ||
|
||
object Named2: | ||
import Conflicting.given | ||
import One.wowStr | ||
import Two.wowInt | ||
def test: Unit = | ||
5.wow // ok | ||
"five".wow // ok | ||
|
||
val Alias = Two | ||
|
||
object Named3: | ||
import Alias.given | ||
import Two.given | ||
def test: Unit = | ||
5.wow // ok | ||
|
||
object Named4: | ||
import Two.given | ||
import Alias.given | ||
def test: Unit = | ||
5.wow // ok |