Skip to content

Commit 32f9deb

Browse files
committed
Do not create symbols for classfile artifacts
These definitions are not supposed to be called from user code, so creating symbols for them is unnecessary. In particular, this fixes various issues with bridges: - Fix #6152: We require `override` to implement bridged abstract method - Fix #8435: Generic signature is missing for bridged method (This PR is only possible thanks to #8499, without this we would use non-bridge symbols as receivers and get IllegalAccessErrors in various cases). Note that this is slightly different from what Scala 2 does: `Type#member` in scalac excludes symbols with the Bridge flag set by default, we can't copy that behavior without more changes on our end since member filtering works differently in both compiler: in Scala 2 if a symbol with an excluded flag overrides a symbol without the flag, the overridden symbol is returned, whereas no symbol is returned in Dotty. In any case, I think that simply not creating the symbols is a more systematic solution, it also makes separate compilation of .java and .scala files work more like joint compilation since under joint compilation we never see the synthetic members generated by javac anyway, this reduces the risk of bugs which appear only under one kind of compilation and not the other.
1 parent 6d1f095 commit 32f9deb

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-1
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ object Flags {
567567
val TermParamOrAccessor: FlagSet = Param | ParamAccessor
568568
val PrivateParamAccessor: FlagSet = ParamAccessor | Private
569569
val PrivateOrSynthetic: FlagSet = Private | Synthetic
570+
val PrivateOrArtifact: FlagSet = Private | Artifact
570571
val ClassTypeParam: FlagSet = Private | TypeParam
571572
val Scala2Trait: FlagSet = Scala2x | Trait
572573
val SyntheticArtifact: FlagSet = Synthetic | Artifact

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class ClassfileParser(
226226
if (method) Flags.Method | methodTranslation.flags(jflags)
227227
else fieldTranslation.flags(jflags)
228228
val name = pool.getName(in.nextChar)
229-
if (!sflags.is(Flags.Private) || name == nme.CONSTRUCTOR) {
229+
if (!sflags.isOneOf(Flags.PrivateOrArtifact) || name == nme.CONSTRUCTOR) {
230230
val member = ctx.newSymbol(
231231
getOwner(jflags), name, sflags, memberCompleter,
232232
getPrivateWithin(jflags), coord = start)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public abstract class A_1 {
2+
public abstract Object f();
3+
4+
public static abstract class B extends A_1 {
5+
@Override
6+
public abstract String f();
7+
}
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class C extends A_1.B {
2+
def f() = ""
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class BuilderBase<A> {
2+
public scala.Option<A> build() { return null; }
3+
}
4+
public class Builder_1<A> extends BuilderBase<A> { }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
val builder: Builder_1[Int] = ???
3+
builder.build(): Option[Int]
4+
}

0 commit comments

Comments
 (0)