Skip to content

Commit e7c01e2

Browse files
committed
Avoid hygiene violations in stripImplicit
1 parent efdfe0e commit e7c01e2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,11 +1502,17 @@ trait Applications extends Compatibility {
15021502
}
15031503

15041504
/** Drop any leading implicit parameter sections */
1505-
def stripImplicit(tp: Type)(using Context): Type = tp match {
1505+
def stripImplicit(tp: Type, wildcardOnly: Boolean = false)(using Context): Type = tp match {
15061506
case mt: MethodType if mt.isImplicitMethod =>
1507-
stripImplicit(resultTypeApprox(mt))
1507+
stripImplicit(resultTypeApprox(mt, wildcardOnly))
15081508
case pt: PolyType =>
1509-
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType)).asInstanceOf[PolyType].flatten
1509+
pt.derivedLambdaType(pt.paramNames, pt.paramInfos,
1510+
stripImplicit(pt.resultType, wildcardOnly = true))
1511+
// can't use TypeParamRefs for parameter references in `resultTypeApprox`
1512+
// since their bounds can refer to type parameters in `pt` that are not
1513+
// bound by the constraint. This can lead to hygiene violations if subsequently
1514+
// `pt` itself is added to the constraint. Test case is run/enrich-gentraversable.scala.
1515+
.asInstanceOf[PolyType].flatten
15101516
case _ =>
15111517
tp
15121518
}

0 commit comments

Comments
 (0)