@@ -366,13 +366,28 @@ trait ConstraintHandling {
366
366
if (tpw eq tp) || dropped.forall(_ frozen_<:< tpw) then tp else tpw
367
367
end dropTransparentTraits
368
368
369
+ /** If `tp` is an applied match type alias which is also an unreducible application
370
+ * of a higher-kinded type to a wildcard argument, widen to the match type's bound,
371
+ * in order to avoid an unreducible application of higher-kinded type ... in inferred type"
372
+ * error in PostTyper. Fixes #11246.
373
+ */
374
+ def widenIrreducible (tp : Type )(using Context ): Type = tp match
375
+ case tp @ AppliedType (tycon, _) if tycon.isLambdaSub && tp.hasWildcardArg =>
376
+ tp.superType match
377
+ case MatchType (bound, _, _) => bound
378
+ case _ => tp
379
+ case _ =>
380
+ tp
381
+
369
382
/** Widen inferred type `inst` with upper `bound`, according to the following rules:
370
383
* 1. If `inst` is a singleton type, or a union containing some singleton types,
371
- * widen (all) the singleton type(s), provided the result is a subtype of `bound`
384
+ * widen (all) the singleton type(s), provided the result is a subtype of `bound`.
372
385
* (i.e. `inst.widenSingletons <:< bound` succeeds with satisfiable constraint)
373
386
* 2. If `inst` is a union type, approximate the union type from above by an intersection
374
387
* of all common base types, provided the result is a subtype of `bound`.
375
- * 3. drop transparent traits from intersections (see @dropTransparentTraits)
388
+ * 3. Widen some irreducible applications of higher-kinded types to wildcard arguments
389
+ * (see @widenIrreducible).
390
+ * 4. Drop transparent traits from intersections (see @dropTransparentTraits).
376
391
*
377
392
* Don't do these widenings if `bound` is a subtype of `scala.Singleton`.
378
393
* Also, if the result of these widenings is a TypeRef to a module class,
@@ -397,7 +412,7 @@ trait ConstraintHandling {
397
412
398
413
val wideInst =
399
414
if isSingleton(bound) then inst
400
- else dropTransparentTraits(widenOr(widenSingle(inst)), bound)
415
+ else dropTransparentTraits(widenIrreducible( widenOr(widenSingle(inst) )), bound)
401
416
wideInst match
402
417
case wideInst : TypeRef if wideInst.symbol.is(Module ) =>
403
418
TermRef (wideInst.prefix, wideInst.symbol.sourceModule)
0 commit comments