Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
block extension method with 2+ type parameter lists
- Loading branch information
1 parent
9e83a60
commit 7927353
Showing
7 changed files
with
64 additions
and
8 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,4 @@ | ||
TestDependentExtension_fail.scala:11: error: Unsupported Scala 3 extension method with secondary type parameter list: extract; found in trait tastytest.DependentExtension. | ||
val res = implicitly[DependentExtension].extract(box)(_ + 1) | ||
^ | ||
1 error |
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,15 @@ | ||
package tastytest | ||
|
||
object TestDependentExtension { | ||
import DependentExtension._ | ||
|
||
def test = { | ||
val box = new Box { | ||
type Repr = Int | ||
val value: Int = 23 | ||
} | ||
val res = implicitly[DependentExtension].extract(box)(_ + 1) | ||
assert(res == 24) | ||
} | ||
|
||
} |
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,4 @@ | ||
TestRealFunctor_fail.scala:6: error: Unsupported Scala 3 extension method with secondary type parameter list: map; found in trait tastytest.RealFunctor. | ||
def map[A, B](fa: List[A])(f: A => B): List[B] = fa.map(f) | ||
^ | ||
1 error |
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,9 @@ | ||
package tastytest | ||
|
||
object TestRealFunctor { | ||
// in this test, we try to implement an extension method that has two type-parameter lists | ||
implicit object ListRealFunctor extends RealFunctor[List] { | ||
def map[A, B](fa: List[A])(f: A => B): List[B] = fa.map(f) | ||
} | ||
|
||
} |
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,20 @@ | ||
package tastytest | ||
|
||
import DependentExtension.Box | ||
|
||
// `DependentExtension` uses two type parameter lists in its `extract` method. the second type parameter list is | ||
// dependent on the first term parameter list. It is unclear how to interpret this. | ||
trait DependentExtension { | ||
extension [B <: Box](b: B) def extract[R >: b.Repr, O](f: R => O): O = f(b.value) | ||
} | ||
|
||
object DependentExtension { | ||
|
||
given DependentExtension with {} | ||
|
||
trait Box { | ||
type Repr | ||
val value: Repr | ||
} | ||
|
||
} |
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,7 @@ | ||
package tastytest | ||
|
||
// This `Functor` uses two type parameter lists in its `map` method. | ||
// In this example, it may be safe to merge the type parameter lists. | ||
trait RealFunctor[F[_]] { | ||
extension [A](fa: F[A]) def map[B](f: A => B): F[B] | ||
} |