@@ -35,12 +35,21 @@ object ProtoTypes {
35
35
def isCompatible (tp : Type , pt : Type )(implicit ctx : Context ): Boolean =
36
36
(tp.widenExpr relaxed_<:< pt.widenExpr) || viewExists(tp, pt)
37
37
38
- /** Test compatibility after normalization in a fresh typerstate. */
39
- def normalizedCompatible (tp : Type , pt : Type )(implicit ctx : Context ): Boolean =
40
- ctx.test { implicit ctx =>
38
+ /** Test compatibility after normalization.
39
+ * Do this in a fresh typerstate unless `keepConstraint` is true.
40
+ */
41
+ def normalizedCompatible (tp : Type , pt : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean = {
42
+ def testCompat (implicit ctx : Context ): Boolean = {
41
43
val normTp = normalize(tp, pt)
42
44
isCompatible(normTp, pt) || pt.isRef(defn.UnitClass ) && normTp.isParameterless
43
45
}
46
+ if (keepConstraint && false )
47
+ tp.widenSingleton match {
48
+ case poly : PolyType => normalizedCompatible(tp, pt, keepConstraint = false )
49
+ case _ => testCompat
50
+ }
51
+ else ctx.test(implicit ctx => testCompat)
52
+ }
44
53
45
54
private def disregardProto (pt : Type )(implicit ctx : Context ): Boolean = pt.dealias match {
46
55
case _ : OrType => true
@@ -89,7 +98,7 @@ object ProtoTypes {
89
98
90
99
/** A trait for prototypes that match all types */
91
100
trait MatchAlways extends ProtoType {
92
- def isMatchedBy (tp1 : Type )(implicit ctx : Context ): Boolean = true
101
+ def isMatchedBy (tp1 : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean = true
93
102
def map (tm : TypeMap )(implicit ctx : Context ): ProtoType = this
94
103
def fold [T ](x : T , ta : TypeAccumulator [T ])(implicit ctx : Context ): T = x
95
104
override def toString : String = getClass.toString
@@ -131,13 +140,13 @@ object ProtoTypes {
131
140
case _ => false
132
141
}
133
142
134
- override def isMatchedBy (tp1 : Type )(implicit ctx : Context ): Boolean = {
143
+ override def isMatchedBy (tp1 : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean = {
135
144
name == nme.WILDCARD || hasUnknownMembers(tp1) ||
136
145
{
137
146
val mbr = if (privateOK) tp1.member(name) else tp1.nonPrivateMember(name)
138
147
def qualifies (m : SingleDenotation ) =
139
148
memberProto.isRef(defn.UnitClass ) ||
140
- tp1.isValueType && compat.normalizedCompatible(NamedType (tp1, name, m), memberProto)
149
+ tp1.isValueType && compat.normalizedCompatible(NamedType (tp1, name, m), memberProto, keepConstraint )
141
150
// Note: can't use `m.info` here because if `m` is a method, `m.info`
142
151
// loses knowledge about `m`'s default arguments.
143
152
mbr match { // hasAltWith inlined for performance
@@ -234,8 +243,8 @@ object ProtoTypes {
234
243
extends UncachedGroundType with ApplyingProto with FunOrPolyProto {
235
244
override def resultType (implicit ctx : Context ): Type = resType
236
245
237
- def isMatchedBy (tp : Type )(implicit ctx : Context ): Boolean =
238
- typer.isApplicable(tp, Nil , unforcedTypedArgs, resultType)
246
+ def isMatchedBy (tp : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean =
247
+ typer.isApplicable(tp, Nil , unforcedTypedArgs, resultType, keepConstraint )
239
248
240
249
def derivedFunProto (args : List [untpd.Tree ] = this .args, resultType : Type , typer : Typer = this .typer): FunProto =
241
250
if ((args eq this .args) && (resultType eq this .resultType) && (typer eq this .typer)) this
@@ -379,7 +388,7 @@ object ProtoTypes {
379
388
380
389
override def resultType (implicit ctx : Context ): Type = resType
381
390
382
- def isMatchedBy (tp : Type )(implicit ctx : Context ): Boolean =
391
+ def isMatchedBy (tp : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean =
383
392
ctx.typer.isApplicable(tp, argType :: Nil , resultType) || {
384
393
resType match {
385
394
case SelectionProto (name : TermName , mbrType, _, _) =>
@@ -422,7 +431,7 @@ object ProtoTypes {
422
431
423
432
override def resultType (implicit ctx : Context ): Type = resType
424
433
425
- override def isMatchedBy (tp : Type )(implicit ctx : Context ): Boolean = {
434
+ override def isMatchedBy (tp : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean = {
426
435
def isInstantiatable (tp : Type ) = tp.widen match {
427
436
case tp : PolyType => tp.paramNames.length == targs.length
428
437
case _ => false
0 commit comments