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