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.
- Don't treat givens as higher priority than implicits. The previous logic was faulty anyway. - Drop special handling of NotGiven in prioritization. The previous logic pretended to do so, but was ineffective. - Don't use old priority in general for implicit/implicit pairs. This would make upgrading to givens a constant struggle. But do use it as a tie breaker in the case of ambiguities. - Also use owner score as a tie breaker if after all other tests we still have an ambiguity.
- Loading branch information
Showing
12 changed files
with
129 additions
and
52 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
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
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,28 @@ | ||
|
||
trait Foo[-T] | ||
trait Bar[-T] extends Foo[T] | ||
|
||
object Test { | ||
|
||
locally: | ||
implicit val fa: Foo[Int] = ??? | ||
implicit val ba: Bar[Int] = ??? | ||
summon[Foo[Int]] // ok | ||
|
||
locally: | ||
implicit val fa: Foo[Int] = ??? | ||
implicit val ba: Bar[Any] = ??? | ||
summon[Foo[Int]] // ok | ||
|
||
locally: | ||
given fa: Foo[Any] = ??? | ||
given ba: Bar[Int] = ??? | ||
summon[Foo[Int]] // error: now ambiguous, | ||
// was resolving to `ba` when using intermediate rules: | ||
// better means specialize, but map all type arguments downwards | ||
|
||
locally: | ||
implicit val fa: Foo[Any] = ??? | ||
implicit val ba: Bar[Int] = ??? | ||
summon[Foo[Int]] // is OK since we fall back to old rules for old-style implicits as a tie breaker | ||
} |
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,24 @@ | ||
/* These tests show various mechanisms available for implicit prioritization. | ||
*/ | ||
import language.`3.6` | ||
|
||
class A // The type for which we infer terms below | ||
class B extends A | ||
|
||
/* First, two schemes that require a pre-planned architecture for how and | ||
* where given instances are defined. | ||
* | ||
* Traditional scheme: prioritize with location in class hierarchy | ||
*/ | ||
class LowPriorityImplicits: | ||
given g1: A() | ||
|
||
object NormalImplicits extends LowPriorityImplicits: | ||
given g2: B() | ||
|
||
def test1 = | ||
import NormalImplicits.given | ||
val x = summon[A] | ||
val _: B = x | ||
val y = summon[B] | ||
val _: B = y |
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import scala.language.implicitConversions | ||
|
||
trait QueryKey[A] | ||
object QueryKey extends QueryKeyInstances | ||
sealed trait QueryKeyInstances: | ||
implicit val stringQueryKey: QueryKey[String] = ??? | ||
|
||
trait QueryValue[-A] | ||
object QueryValue extends QueryValueInstances | ||
sealed trait QueryValueInstances1: | ||
implicit final val stringQueryValue: QueryValue[String] = ??? | ||
implicit final val noneQueryValue: QueryValue[None.type] = ??? | ||
|
||
sealed trait QueryValueInstances extends QueryValueInstances1: | ||
implicit final def optionQueryValue[A: QueryValue]: QueryValue[Option[A]] = ??? | ||
|
||
trait QueryKeyValue[A] | ||
object QueryKeyValue: | ||
implicit def tuple2QueryKeyValue[K: QueryKey, V: QueryValue]: QueryKeyValue[(K, V)] = ??? | ||
|
||
|
||
@main def Test = summon[QueryKeyValue[(String, None.type)]] | ||
|
||
/*(using | ||
QueryKeyValue.tuple2QueryKeyValue[String, None.type]( | ||
QueryKey.stringQueryKey, | ||
QueryValue.optionQueryValue[A]))*/ | ||
|
||
// 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
barFoo | ||
fooFoo |
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