Skip to content

Commit

Permalink
test more variants
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Mar 8, 2023
1 parent 132001e commit 27f4e30
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tests/pos/i16920-boxed.scala
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
88 changes: 88 additions & 0 deletions tests/pos/i16920-typeclass.scala
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

0 comments on commit 27f4e30

Please sign in to comment.