-
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.
Fix problem with extension methods in givens
For these we need an eligibility pre-check. That pre-check did not skip leading implicit parameters, so failed to recognize eligible extension methods.
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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,37 @@ | ||
trait Food | ||
case class Banana(color: String) extends Food | ||
|
||
trait Diet[A <: Animal]: | ||
type F <: Food | ||
def food: Seq[F] | ||
|
||
trait Animal | ||
object Animal: | ||
extension [A <: Animal](using diet: Diet[A])(animal: A) def food1 = diet.food | ||
extension [A <: Animal](animal: A)(using diet: Diet[A]) def food2 = diet.food | ||
|
||
extension [A <: Animal](using diet: Diet[A])(animal: A) def food3 = diet.food | ||
extension [A <: Animal](animal: A)(using diet: Diet[A]) def food4 = diet.food | ||
|
||
trait Monkey extends Animal | ||
|
||
given Diet[Monkey] with | ||
type F = Banana | ||
def food: Seq[Banana] = Seq(new Banana("yellow"), Banana("green")) | ||
|
||
trait FoodOps | ||
given FoodOps with | ||
extension [A <: Animal](using diet: Diet[A])(animal: A) def food5 = diet.food | ||
extension [A <: Animal](animal: A)(using diet: Diet[A]) def food6 = diet.food | ||
|
||
|
||
val monkey = new Monkey {} | ||
|
||
val foods = Seq( | ||
monkey.food1, // doesn't compile | ||
monkey.food2, // compiles | ||
monkey.food3, // compiles | ||
monkey.food4, // compiles | ||
monkey.food5, // doesn't compile | ||
monkey.food6, // compiles | ||
) |