forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Insert conversions also on selections wrapped in type applications
In i12708.scala, the problematic function was a selection `qual.m[tvs]` that was already applied to type variables. In that case we need to backtrack, forget the type variables and try to insert a conversion or extension method on `qual`. Fixes scala#12708
- Loading branch information
Showing
2 changed files
with
43 additions
and
5 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,37 @@ | ||
import language.implicitConversions | ||
|
||
trait AdditiveSemigroup[A] | ||
|
||
final class AdditiveSemigroupOps[A](lhs: A)(implicit as: AdditiveSemigroup[A]) { | ||
def +(rhs: A): A = ??? | ||
def ^(rhs: A): A = ??? | ||
} | ||
|
||
trait AdditiveSemigroupSyntax { | ||
implicit def additiveSemigroupOps[A: AdditiveSemigroup](a: A): AdditiveSemigroupOps[A] = | ||
new AdditiveSemigroupOps(a) | ||
} | ||
|
||
object syntax { | ||
object additiveSemigroup extends AdditiveSemigroupSyntax | ||
} | ||
|
||
object App { | ||
|
||
def main(args: Array[String]): Unit = { | ||
import syntax.additiveSemigroup._ | ||
|
||
implicit def IntAlgebra[A]: AdditiveSemigroup[Map[Int, A]] = ??? | ||
|
||
def res[A]: Map[Int, A] = { | ||
val a: Map[Int, A] = Map.empty | ||
val b: Map[Int, A] = Map.empty | ||
// Calls the operator on AdditiveSemigroupOps | ||
a ^ b | ||
// Calls the operator + on AdditiveSemigroupOps only in Scala 2 | ||
// In Scala 3 tries to call `+` on Map | ||
a + b | ||
} | ||
} | ||
|
||
} |