Skip to content

Fix #6238 (take 3): Strip WildcardType when applying arguments #6252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object Decorators {
}
}

final val MaxFilterRecursions = 1000
final val MaxFilterRecursions = 100

/** Implements filterConserve, zipWithConserve methods
* on lists that avoid duplication of list nodes where feasible.
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ object TypeApplications {
def apply(t: Type): Type = t match {
case t @ AppliedType(tycon, args1) if tycon.typeSymbol.isClass =>
t.derivedAppliedType(apply(tycon), args1.mapConserve(applyArg))
case t @ RefinedType(parent, name, TypeAlias(info)) =>
t.derivedRefinedType(apply(parent), name, applyArg(info).bounds)
case p: TypeParamRef if p.binder == tycon =>
args(p.paramNum) match {
case TypeBounds(lo, hi) =>
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,14 @@ object ProtoTypes {
else if (tp.symbol.isStatic || (tp.prefix `eq` NoPrefix)) tp
else tp.derivedSelect(wildApprox(tp.prefix, theMap, seen))
case tp @ AppliedType(tycon, args) =>
def wildToBounds(tp: Type) = tp match {
case WildcardType(tp: TypeBounds) => tp
case tp => tp
}
wildApprox(tycon, theMap, seen) match {
case _: WildcardType => WildcardType // this ensures we get a * type
case tycon1 => tp.derivedAppliedType(tycon1,
args.mapConserve(arg => wildApprox(arg, theMap, seen)))
args.mapConserve(arg => wildToBounds(wildApprox(arg, theMap, seen))))
}
case tp: RefinedType => // default case, inlined for speed
tp.derivedRefinedType(
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/hkRefAlias.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Bar
class X
class Y extends X

object Test {
type G[X] = Bar { type R = X }

implicitly[G[_] =:= (Bar { type R })]
implicitly[G[_ >: Y <: X] =:= (Bar { type R >: Y <: X })]
}
121 changes: 121 additions & 0 deletions tests/pos/i6238.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
object K1 {
class Foo[T]

class Bar[F[_]]
object Bar {
implicit def barF[F[_]](implicit fooF: Foo[Bar[F]]): Bar[F] = null
}

class A[T]
object A {
implicit def fooA[F[_[_]]](implicit barB: F[B]): Foo[F[A]] = null
}

class B[T]
object B {
implicit def fooB[F[_[_]]]: Foo[F[B]] = null
}
}

object K1U {
class Foo[T]

class Bar[F[_ <: Int]]
object Bar {
implicit def barF[F[_ <: Int]](implicit fooF: Foo[Bar[F]]): Bar[F] = null
}

class A[T <: Int]
object A {
implicit def fooA[F[_[_ <: Int]]](implicit barB: F[B]): Foo[F[A]] = null
}

class B[T <: Int]
object B {
implicit def fooB[F[_[_ <: Int]]]: Foo[F[B]] = null
}
}

object K1L {
class Foo[T]

class Bar[F[_ >: Int]]
object Bar {
implicit def barF[F[_ >: Int]](implicit fooF: Foo[Bar[F]]): Bar[F] = null
}

class A[T >: Int]
object A {
implicit def fooA[F[_[_ >: Int]]](implicit barB: F[B]): Foo[F[A]] = null
}

class B[T >: Int]
object B {
implicit def fooB[F[_[_ >: Int]]]: Foo[F[B]] = null
}
}

object K11 {
class Foo[T]

class Bar[F[_[_]]]
object Bar {
implicit def barF[F[_[_]]](implicit fooF: Foo[Bar[F]]): Bar[F] = null
}

class A[T[_]]
object A {
implicit def fooA[F[_[_[_]]]](implicit barB: F[B]): Foo[F[A]] = null
}

class B[T[_]]
object B {
implicit def fooB[F[_[_[_]]]]: Foo[F[B]] = null
}
}

object K2 {
class Foo[T]

class Bar[F[_, _]]
object Bar {
implicit def barF[F[_, _]](implicit fooF: Foo[Bar[F]]): Bar[F] = null
}

class A[T, U]
object A {
implicit def fooA[F[_[_, _]]](implicit barB: F[B]): Foo[F[A]] = null
}

class B[T, U]
object B {
implicit def fooB[F[_[_, _]]]: Foo[F[B]] = null
}
}

object Test {
{
import K1._
implicitly[Bar[A]]
}

{
import K1U._
implicitly[Bar[A]]
}

{
import K1L._
implicitly[Bar[A]]
}

{
import K11._
implicitly[Bar[A]]
}

{
import K2._
implicitly[Bar[A]]
}
}