@@ -188,20 +188,33 @@ object ProtoTypes {
188
188
case _ => false
189
189
190
190
override def isMatchedBy (tp1 : Type , keepConstraint : Boolean )(using Context ): Boolean =
191
- name == nme.WILDCARD || hasUnknownMembers(tp1) ||
192
- {
193
- val mbr = if (privateOK) tp1.member(name) else tp1.nonPrivateMember(name)
194
- def qualifies (m : SingleDenotation ) =
195
- val isAccessible = ! m.symbol.exists || m.symbol.isAccessibleFrom(tp1, superAccess = true )
196
- isAccessible
197
- && (memberProto.isRef(defn.UnitClass )
198
- || tp1.isValueType && compat.normalizedCompatible(NamedType (tp1, name, m), memberProto, keepConstraint))
199
- // Note: can't use `m.info` here because if `m` is a method, `m.info`
200
- // loses knowledge about `m`'s default arguments.
201
- mbr match { // hasAltWith inlined for performance
202
- case mbr : SingleDenotation => mbr.exists && qualifies(mbr)
203
- case _ => mbr hasAltWith qualifies
204
- }
191
+ name == nme.WILDCARD
192
+ || hasUnknownMembers(tp1)
193
+ || {
194
+ try
195
+ val mbr = if privateOK then tp1.member(name) else tp1.nonPrivateMember(name)
196
+ def qualifies (m : SingleDenotation ) =
197
+ val isAccessible = ! m.symbol.exists || m.symbol.isAccessibleFrom(tp1, superAccess = true )
198
+ isAccessible
199
+ && (memberProto.isRef(defn.UnitClass )
200
+ || tp1.isValueType && compat.normalizedCompatible(NamedType (tp1, name, m), memberProto, keepConstraint))
201
+ // Note: can't use `m.info` here because if `m` is a method, `m.info`
202
+ // loses knowledge about `m`'s default arguments.
203
+ mbr match // hasAltWith inlined for performance
204
+ case mbr : SingleDenotation => mbr.exists && qualifies(mbr)
205
+ case _ => mbr hasAltWith qualifies
206
+ catch case ex : TypeError =>
207
+ // A scenario where this can happen is in pos/15673.scala:
208
+ // We have a type `CC[A]#C` where `CC`'s upper bound is `[X] => Any`, but
209
+ // the current constraint stipulates CC <: SeqOps[...], where `SeqOps` defines
210
+ // the `C` parameter. We try to resolve this using `argDenot` but `argDenot`
211
+ // consults the base type of `CC`, which is not `SeqOps`, so it does not
212
+ // find a corresponding argument. In fact, `argDenot` is not allowed to
213
+ // consult short-lived things like the current constraint, so it has no other
214
+ // choice. The problem will be healed later, when normal selection fails
215
+ // and we try to instantiate type variables to compensate. But we have to make
216
+ // sure we do not issue a type error before we get there.
217
+ false
205
218
}
206
219
207
220
def underlying (using Context ): Type = WildcardType
0 commit comments