Skip to content

Commit ec2d7d6

Browse files
committed
Refine lookupRefined for Wildcard prefixes
lookupRefined used to fall back to unbounded Wildcard, given a Wildcard prefix. But that loses bounds when called from wildApprox, which in turn loses companion objects in the implicit scope of a type. In `i553-shuffle.scala` this happened because we projected with #Apply on a type that approximated to a bounded wildcard. The fix keeps the bounds, projecting in turn on them.
1 parent eac33f0 commit ec2d7d6

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/dotty/tools/dotc/core/Types.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,13 @@ object Types {
869869
case SkolemType(tp) =>
870870
tp.lookupRefined(name)
871871
case pre: WildcardType =>
872-
WildcardType
872+
pre.optBounds match {
873+
case TypeBounds(lo, hi) if name.isTypeName =>
874+
// for term names, forming a Termref with just the name risks losing overloaded instance
875+
WildcardType(TypeBounds(NamedType(lo, name), NamedType(hi, name)))
876+
case _ =>
877+
WildcardType
878+
}
873879
case pre: TypeRef =>
874880
pre.info match {
875881
case TypeAlias(alias) => loop(alias, resolved)

tests/pos/i553-shuffle.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import scala.util.Random
2-
import scala.collection.immutable.List._
32
object Test {
43
def test = {
54
val rand = new Random
6-
rand.shuffle(List(1,2))//(List.canBuildFrom[Int]) // fails
5+
rand.shuffle(List(1,2))// infers implicit argument list (List.canBuildFrom[Int])
76
}
87
}
File renamed without changes.

0 commit comments

Comments
 (0)