Skip to content

Commit 27f4e30

Browse files
committed
test more variants
1 parent 132001e commit 27f4e30

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

tests/pos/i16920-boxed.scala

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import language.experimental.relaxedExtensionImports
2+
3+
import scala.annotation.targetName
4+
trait Foo[+T]
5+
6+
def foo[T](t: T): Foo[T] = new Foo[T] {}
7+
8+
object One:
9+
extension (s: Foo[String])
10+
def wow: Unit = println(s)
11+
12+
object Two:
13+
extension (i: Foo[Int])
14+
def wow: Unit = println(i)
15+
16+
object Three:
17+
extension (s: Foo[String])
18+
@targetName("wowString")
19+
def wow: Unit = println(s)
20+
extension (i: Foo[Int])
21+
@targetName("wowInt")
22+
def wow: Unit = println(i)
23+
24+
object Four:
25+
implicit class WowString(s: Foo[String]):
26+
def wow: Unit = println(s)
27+
28+
object Five:
29+
implicit class WowInt(i: Foo[Int]):
30+
def wow: Unit = println(i)
31+
32+
object Compiles:
33+
import Three._
34+
def test: Unit =
35+
foo(5).wow
36+
foo("five").wow
37+
38+
object AlsoCompiles:
39+
import Four._
40+
import Five._
41+
def test: Unit =
42+
foo(5).wow
43+
foo("five").wow
44+
45+
object UsedToFail:
46+
import One._
47+
import Compiles.*
48+
import Two._
49+
def test: Unit =
50+
foo(5).wow
51+
foo("five").wow
52+
53+
object Conflicting:
54+
extension (i: Foo[Int])
55+
def wow: Unit = println(i)
56+
57+
object Named:
58+
import One.wow
59+
import Two.wow
60+
import Conflicting._
61+
def test: Unit =
62+
foo(5).wow // ok
63+
foo("five").wow // ok
64+
65+
object Named2:
66+
import Conflicting._
67+
import One.wow
68+
import Two.wow
69+
def test: Unit =
70+
foo(5).wow // ok
71+
foo("five").wow // ok
72+
73+
val Alias = Two
74+
75+
object Named3:
76+
import Alias._
77+
import Two._
78+
def test: Unit =
79+
foo(5).wow // ok
80+
81+
object Named4:
82+
import Two._
83+
import Alias._
84+
def test: Unit =
85+
foo(5).wow // ok

tests/pos/i16920-typeclass.scala

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import language.experimental.relaxedExtensionImports
2+
// evolve tests/pos/i16920.scala to abstract out Wow to a typeclass, more like the typical library use case
3+
4+
trait Wow[T]:
5+
extension (t: T)
6+
def wow: Unit
7+
8+
object One:
9+
given wowStr: Wow[String] with
10+
extension (s: String)
11+
def wow: Unit = println(s)
12+
13+
object Two:
14+
given wowInt: Wow[Int] with
15+
extension (i: Int)
16+
def wow: Unit = println(i)
17+
18+
object Three:
19+
given wowStr: Wow[String] with
20+
extension (s: String)
21+
def wow: Unit = println(s)
22+
given wowInt: Wow[Int] with
23+
extension (i: Int)
24+
def wow: Unit = println(i)
25+
26+
object Four:
27+
implicit class WowString(s: String):
28+
def wow: Unit = println(s)
29+
30+
object Five:
31+
implicit class WowInt(i: Int):
32+
def wow: Unit = println(i)
33+
34+
object Compiles:
35+
import Three.given
36+
def test: Unit =
37+
5.wow
38+
"five".wow
39+
40+
object AlsoCompiles:
41+
import Four.given
42+
import Five.given
43+
def test: Unit =
44+
5.wow
45+
"five".wow
46+
47+
object UsedToFail:
48+
import One.given
49+
import Compiles.*
50+
import Two.given
51+
def test: Unit =
52+
5.wow
53+
"five".wow
54+
55+
object Conflicting:
56+
given wowInt: Wow[Int] with
57+
extension (i: Int)
58+
def wow: Unit = println(i)
59+
60+
object Named:
61+
import One.wowStr
62+
import Two.wowInt
63+
import Conflicting.given
64+
def test: Unit =
65+
5.wow // ok
66+
"five".wow // ok
67+
68+
object Named2:
69+
import Conflicting.given
70+
import One.wowStr
71+
import Two.wowInt
72+
def test: Unit =
73+
5.wow // ok
74+
"five".wow // ok
75+
76+
val Alias = Two
77+
78+
object Named3:
79+
import Alias.given
80+
import Two.given
81+
def test: Unit =
82+
5.wow // ok
83+
84+
object Named4:
85+
import Two.given
86+
import Alias.given
87+
def test: Unit =
88+
5.wow // ok

0 commit comments

Comments
 (0)