Skip to content

Commit 2a41413

Browse files
committed
Fix signatures involving WildcardTypes
A `WildcardType` never appears in the type of a tree, but it can appear in an expected type and because TypeComparer checks if `tp1.signature consistentParams tp2.signature`, we can end up calling `sigName` on a `WildcardType`. Before this commit, the result was either a custom type name or the upper-bound of the wildcard, but both of these options means that `consistentParams` could return false in situations where the two method types would in fact match. We fix this by always returning `tpnme.Uninstantiated`, meaning that `consistentParams` will always allow a wildcard to match any other type. This does not cause any over-approximation because the TypeComparer will always check that the actual types match after checking that the signatures match. Also use tpnme.ERROR instead of tpnme.Wildcard for ErrorType and NoType to make it easier to spot their usage. Fixes #11481.
1 parent 1e484e5 commit 2a41413

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,10 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
821821
sigName(this(tp))
822822
case tp: TypeProxy =>
823823
sigName(tp.underlying)
824-
case _: ErrorType | WildcardType | NoType =>
825-
tpnme.WILDCARD
826824
case tp: WildcardType =>
827-
sigName(tp.optBounds)
825+
tpnme.Uninstantiated
826+
case _: ErrorType | NoType =>
827+
tpnme.ERROR
828828
case _ =>
829829
val erasedTp = this(tp)
830830
assert(erasedTp ne tp, tp)

tests/pos/i11481.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
case class Foo[F[_]](f: {def f(x: F[Int]): Object})
2+
case class Bar[F[_], G[_]](f: [B] => F[B] => G[B])

0 commit comments

Comments
 (0)