Skip to content

Changes to wildApprox #1054

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ object Implicits {
case mt: MethodType =>
mt.isImplicit ||
mt.paramTypes.length != 1 ||
!(argType relaxed_<:< wildApprox(mt.paramTypes.head)(ctx.fresh.setExploreTyperState))
!(argType relaxed_<:< wildApprox(mt.paramTypes.head, poly)(ctx.fresh.setExploreTyperState))
case rtp =>
discardForView(wildApprox(rtp), argType)
discardForView(wildApprox(rtp, poly), argType)
}
case tpw: TermRef =>
false // can't discard overloaded refs
Expand Down
20 changes: 18 additions & 2 deletions src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,19 @@ object ProtoTypes {
}
}

/** Like wildApprox, but assume that all parameters of `disregarded` are not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird to say "Like wildApprox" when this method is called wildApprox too, maybe use another name, or say, "Like the other overload of wildApprox"?

* bound in current constraint. This is necessary because an instance of
* the type of a polymorphic function might already be part of the current
* constraint when we try to check another occurrence of the same polymorphic
* function for eligibility. An example is in i1044.scala where one expression
* requires two implicit calls of the same refArrayOps method. When approximating
* the parameter types of such a method we should always ignore type parameters of
* the method itself, even though some of these parameters might still be
* bound in the constraint.
*/
final def wildApprox(tp: Type, disregarded: PolyType)(implicit ctx: Context): Type =
wildApprox(tp, new WildApproxMap(disregarded))

/** Approximate occurrences of parameter types and uninstantiated typevars
* by wildcard types.
*/
Expand All @@ -391,7 +404,10 @@ object ProtoTypes {
case tp: TypeAlias => // default case, inlined for speed
tp.derivedTypeAlias(wildApprox(tp.alias, theMap))
case tp @ PolyParam(poly, pnum) =>
ctx.typerState.constraint.entry(tp) match {
val constrOrInst =
if (theMap != null && (poly eq theMap.disregarded)) NoType
else ctx.typerState.constraint.entry(tp)
constrOrInst match {
case bounds: TypeBounds => wildApprox(WildcardType(bounds))
case NoType => WildcardType(wildApprox(poly.paramBounds(pnum)).bounds)
case inst => wildApprox(inst)
Expand Down Expand Up @@ -426,7 +442,7 @@ object ProtoTypes {
(if (theMap != null) theMap else new WildApproxMap).mapOver(tp)
}

private[ProtoTypes] class WildApproxMap(implicit ctx: Context) extends TypeMap {
private[ProtoTypes] class WildApproxMap(val disregarded: Type = NoType)(implicit ctx: Context) extends TypeMap {
def apply(tp: Type) = wildApprox(tp, this)
}

Expand Down
3 changes: 3 additions & 0 deletions tests/pos/i1044.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
val x = ???.getClass.getMethods.head.getParameterTypes.mkString(",")
}