File tree 2 files changed +40
-1
lines changed
compiler/src/dotty/tools/dotc/typer
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -409,7 +409,7 @@ trait ImplicitRunInfo { self: RunInfo =>
409
409
case tp : AppliedType if ! tp.tycon.typeSymbol.isClass =>
410
410
def applyArg (arg : Type ) = arg match {
411
411
case TypeBounds (lo, hi) => AndType .make(lo, hi)
412
- case _ : WildcardType => defn. AnyType
412
+ case WildcardType ( TypeBounds (lo, hi)) => AndType .make(lo, hi)
413
413
case _ => arg
414
414
}
415
415
(apply(tp.tycon) /: tp.args)((tc, arg) => AndType .make(tc, applyArg(arg)))
Original file line number Diff line number Diff line change
1
+ trait Tagged [T ]
2
+
3
+ object Tagged {
4
+ type Aux [T , UNUSED ] = Tagged [T ]
5
+ }
6
+
7
+ trait Fun [R ] {
8
+ type Out
9
+ }
10
+
11
+ object Fun extends Fun0 {
12
+ // In Dotty there is a difference between asking for Tagged.Aux[T, Int]
13
+ // and asking for Tagged[T]. In the former case the companion of T is
14
+ // not considered as a valid scope during implicit search. In scalac
15
+ // both cases are treated equally.
16
+ implicit def tagged [T ](implicit t : Tagged .Aux [T , Int ]): Fun [T ] { type Out = Int } = ???
17
+ }
18
+
19
+ trait Fun0 {
20
+ implicit def default [T ]: Fun [T ] { type Out = String } = ???
21
+ }
22
+
23
+ object FunDemo extends App {
24
+ case class A (x : Int , y : String )
25
+ object A {
26
+ implicit val tag : Tagged [A ] = ???
27
+ }
28
+
29
+ // Precise version of implicitly that keeps type members
30
+ def the [T <: AnyRef ](implicit ev : T ): ev.type = ev
31
+
32
+ val adhl = the[Fun [A ]]
33
+
34
+ // Compiles in scalac: the tagged case wins the implicit search using A.tag
35
+ // Does not compile in Dotty: because of Tagged.Aux[T, _] the companion
36
+ // object of T is not explored during the search,
37
+ // it fallbacks to default (type Out = String)
38
+ identity[Fun [A ] { type Out = Int }](adhl)
39
+ }
You can’t perform that action at this time.
0 commit comments