@@ -1101,17 +1101,25 @@ class Namer { typer: Typer =>
11011101
11021102 def addWildcardForwarders (seen : List [TermName ], span : Span ): Unit =
11031103 val nonContextual = mutable.HashSet (seen : _* )
1104- for mbr <- path.tpe.membersBasedOnFlags(required = EmptyFlags , excluded = PrivateOrSynthetic ) do
1105- if ! mbr.symbol.isSuperAccessor then
1106- // Scala 2 superaccessors have neither Synthetic nor Artfact set, so we
1107- // need to filter them out here (by contrast, Scala 3 superaccessors are Artifacts)
1108- val alias = mbr.name.toTermName
1109- if mbr.symbol.is(Given ) then
1110- if ! seen.contains(alias) && mbr.matchesImportBound(givenBound) then
1111- addForwarder(alias, mbr, span)
1112- else if ! nonContextual.contains(alias) && mbr.matchesImportBound(wildcardBound) then
1113- nonContextual += alias
1114- addWildcardForwardersNamed(alias, span)
1104+ for
1105+ mbr <- path.tpe.membersBasedOnFlags(required = EmptyFlags , excluded = Artifact | Private )
1106+ if ! mbr.symbol.isSuperAccessor
1107+ do
1108+ val alias = mbr.name.toTermName
1109+ val isSynthetic = mbr.filterWithFlags(required = Synthetic , excluded = EmptyFlags ).exists
1110+ // Scala 2 superaccessors have neither Synthetic nor Artfact set, so we
1111+ // need to filter them out here (by contrast, Scala 3 superaccessors are Artifacts)
1112+ if mbr.symbol.is(Given ) then
1113+ val eligable = ! seen.contains(alias) && mbr.matchesImportBound(givenBound)
1114+ if
1115+ eligable && (! isSynthetic || mbr.symbol.exists
1116+ && mbr.symbol.isCoDefinedGiven(mbr.info.finalResultType.typeSymbol)
1117+ )
1118+ then
1119+ addForwarder(alias, mbr, span)
1120+ else if ! isSynthetic && ! nonContextual.contains(alias) && mbr.matchesImportBound(wildcardBound) then
1121+ nonContextual += alias
1122+ addWildcardForwardersNamed(alias, span)
11151123
11161124 def addForwarders (sels : List [untpd.ImportSelector ], seen : List [TermName ]): Unit = sels match
11171125 case sel :: sels1 =>
0 commit comments