Skip to content

Fix #9967: Don't add forwarders for super accessors #9978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ object Flags {
val AccessorOrDeferred: FlagSet = Accessor | Deferred
val PrivateAccessor: FlagSet = Accessor | Private
val AccessorOrSynthetic: FlagSet = Accessor | Synthetic
val JavaOrPrivateOrSynthetic: FlagSet = Artifact | JavaDefined | Private | Synthetic
val PrivateOrSynthetic: FlagSet = Artifact | Private | Synthetic
val EnumCase: FlagSet = Case | Enum
val CovariantLocal: FlagSet = Covariant | Local // A covariant type parameter
val ContravariantLocal: FlagSet = Contravariant | Local // A contravariant type parameter
Expand All @@ -540,7 +542,6 @@ object Flags {
val InlineByNameProxy: FlagSet = InlineProxy | Method
val JavaEnumTrait: FlagSet = JavaDefined | Enum // A Java enum trait
val JavaEnumValue: FlagSet = JavaDefined | EnumValue // A Java enum value
val JavaOrPrivateOrSynthetic: FlagSet = JavaDefined | Private | Synthetic
val StaticProtected: FlagSet = JavaDefined | JavaStatic | Protected // Java symbol which is `protected` and `static`
val JavaModule: FlagSet = JavaDefined | Module // A Java companion object
val JavaInterface: FlagSet = JavaDefined | NoInits | Trait
Expand All @@ -561,7 +562,6 @@ object Flags {
val ValidForeverFlags: FlagSet = Package | Permanent | Scala2SpecialFlags
val TermParamOrAccessor: FlagSet = Param | ParamAccessor
val PrivateParamAccessor: FlagSet = ParamAccessor | Private
val PrivateOrSynthetic: FlagSet = Private | Synthetic
val PrivateOrArtifact: FlagSet = Private | Artifact
val ClassTypeParam: FlagSet = Private | TypeParam
val Scala2Trait: FlagSet = Scala2x | Trait
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ResolveSuper extends MiniPhase with IdentityDenotTransformer { thisPhase =
override def transformDefDef(ddef: DefDef)(using Context): Tree = {
val meth = ddef.symbol.asTerm
if (meth.isSuperAccessor && !meth.is(Deferred)) {
assert(ddef.rhs.isEmpty)
assert(ddef.rhs.isEmpty, ddef.symbol)
val cls = meth.owner.asClass
val ops = new MixinOps(cls, thisPhase)
import ops._
Expand Down
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1029,10 +1029,13 @@ class Namer { typer: Typer =>

def addWildcardForwarders(seen: List[TermName], span: Span): Unit =
for mbr <- path.tpe.membersBasedOnFlags(required = EmptyFlags, excluded = PrivateOrSynthetic) do
val alias = mbr.name.toTermName
if !seen.contains(alias)
&& mbr.matchesImportBound(if mbr.symbol.is(Given) then givenBound else wildcardBound)
then addForwarder(alias, mbr, span)
if !mbr.symbol.isSuperAccessor then
// Scala 2 superaccessors have neither Synthetic nor Artfact set, so we
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I guess we could set these flags for superaccessors in Scala2Unpickler, that way we're sure they're treated like the dotty ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider that if we find other areas where the missing flag for super accessors messes things up. As it is now, we exercise the test a lot less often than if we have to test every symbol read from Scala 2 for whether it is a super accessor.

// need to filter them out here (by contrast, Scala 3 superaccessors are Artifacts)
val alias = mbr.name.toTermName
if !seen.contains(alias)
&& mbr.matchesImportBound(if mbr.symbol.is(Given) then givenBound else wildcardBound)
then addForwarder(alias, mbr, span)

def addForwarders(sels: List[untpd.ImportSelector], seen: List[TermName]): Unit = sels match
case sel :: sels1 =>
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i9967.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import collection.mutable

class MaxSizeMap[K, V](maxSize: Int)(using o: Ordering[K]):
val sortedMap: mutable.TreeMap[K, V] = mutable.TreeMap.empty[K, V](o)

export sortedMap._