Skip to content

Commit f5b7c97

Browse files
committed
Fix handling of parameterized implicits in import bounds
Need to use normalizedCompatible instead of `<:<`.
1 parent c8ad8ec commit f5b7c97

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

compiler/src/dotty/tools/dotc/typer/ImportInfo.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import util.SimpleIdentityMap
1010
import Symbols._, Names._, Types._, Contexts._, StdNames._, Flags._
1111
import Implicits.RenamedImplicitRef
1212
import printing.Texts.Text
13+
import ProtoTypes.NoViewsAllowed.normalizedCompatible
1314
import Decorators._
1415

1516
object ImportInfo {
@@ -127,7 +128,8 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
127128
val renamed = forwardMapping(ref.name)
128129
if (renamed == ref.name) ref :: Nil
129130
else if (renamed != null) new RenamedImplicitRef(ref, renamed) :: Nil
130-
else if (!impliedBound.exists || (ref <:< impliedBound)) ref :: Nil
131+
else if (!impliedBound.exists ||
132+
normalizedCompatible(ref, impliedBound, keepConstraint = false)) ref :: Nil
131133
else Nil
132134
}
133135
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ class Typer extends Namer
190190
if (imp.importImplied) reqd |= Implied else excl |= Implied
191191
var denot = pre.memberBasedOnFlags(name, reqd, excl).accessibleFrom(pre)(refctx)
192192
if (checkBounds && imp.impliedBound.exists)
193-
denot = denot.filterWithPredicate(_.info <:< imp.impliedBound)
193+
denot = denot.filterWithPredicate(mbr =>
194+
NoViewsAllowed.normalizedCompatible(mbr.info, imp.impliedBound, keepConstraint = false))
194195

195196
// Pass refctx so that any errors are reported in the context of the
196197
// reference instead of the

tests/run/implied-for.scala

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,36 @@ object Test extends App {
2222

2323
assert(the[T].isInstanceOf[B])
2424
assert(the[D[Int]].isInstanceOf[D[_]])
25-
}
25+
}
26+
27+
class Ordering[T]
28+
class ExecutionContext
29+
class Monoid[T]
30+
31+
object Instances {
32+
implied intOrd for Ordering[Int]
33+
implied listOrd[T] for Ordering[List[T]] given Ordering[T]
34+
implied ec for ExecutionContext
35+
implied im for Monoid[Int]
36+
}
37+
38+
object Test2 {
39+
import implied Instances.{for Ordering[_], ExecutionContext}
40+
val x = intOrd
41+
val y = listOrd[Int]
42+
val z = ec
43+
the[Ordering[Int]]
44+
the[Ordering[List[Int]]]
45+
the[ExecutionContext]
46+
}
47+
48+
object Test3 {
49+
import implied Instances.{for Ordering[_]}
50+
val x = intOrd
51+
val y = listOrd[Int]
52+
val z = im
53+
the[Ordering[Int]]
54+
the[Ordering[List[Int]]]
55+
the[Monoid[Int]]
56+
}
57+

0 commit comments

Comments
 (0)