-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parametric extension methods (#1490)
- Loading branch information
1 parent
b46f01f
commit 75711da
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
frontends/benchmarks/dotty-specific/valid/ParametricExtensionMetho.scala
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,16 @@ | ||
object ParametricExtensionMetho { | ||
sealed trait Opt[+T] | ||
case object Non extends Opt[Nothing] // Where is Oui? | ||
final case class Som[+T](content: T) extends Opt[T] | ||
|
||
extension[T](m: Opt[T]) | ||
def flatMap[U](f: T => Opt[U]): Opt[U] = | ||
m match | ||
case Non => Non | ||
case Som(t) => f(t) | ||
|
||
def test[A, B](a: A, f: A => B): Unit = | ||
assert(Som(a).flatMap(a => Som(f(a))) == Som(f(a))) | ||
assert(Som(a).flatMap(_ => Non) == Non) | ||
assert((Non : Opt[A]).flatMap(a => Som(f(a))) == Non) | ||
} |
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