Skip to content

Commit 115e880

Browse files
committed
mark synthesized protected member as notPROTECTED,
TODO: this doesn't work because protected[this] is supposed to be a variance checking escape hatch, and making these notPROTECTED here will trigger errors in refchecks so that it stays in overriding relation with the trait member in later phases make notPROTECTED a bit later? protected local variance bla
1 parent b56ca2f commit 115e880

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/compiler/scala/tools/nsc/transform/Fields.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,17 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
128128
// required for private vals in traits
129129
accessor.makeNotPrivate(clazz)
130130

131+
// Need to mark as notPROTECTED, so that it's carried over to the synthesized member in subclasses,
132+
// since the trait member will receive this flag later in ExplicitOuter, but the synthetic subclass member will not.
133+
// If we don't add notPROTECTED to the synthesized one, the member will not be seen as overriding the trait member.
134+
// Therefore, addForwarders's call to membersBasedOnFlags would see the deferred member in the trait,
135+
// instead of the concrete (desired) one in the class
136+
if (accessor.isProtected) accessor setFlag notPROTECTED
137+
131138
// trait members cannot be final (but the synthesized ones should be)
132-
// LOCAL no longer applies (already made not-private)
133-
accessor resetFlag (FINAL | LOCAL)
139+
// must not reset LOCAL, as we must maintain protected[this]ness to allow that variance hole
140+
// (not sure why this only problem only arose when we started setting the notPROTECTED flag)
141+
accessor resetFlag (FINAL)
134142

135143
// derive trait setter after calling makeNotPrivate (so that names are mangled consistently)
136144
if (memoizedGetter) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait T {
2+
// Need to mark the synthesized member in the object's module class as notPROTECTED,
3+
// since the trait member will receive this flag later.
4+
// If we don't add notPROTECTED to the synthesized one, the member will not be seen as overriding the trait member.
5+
// Therefore, addForwarders's call to membersBasedOnFlags would see the deferred member in the trait,
6+
// instead of the concrete (desired) one in the class, and thus not create the static forwarder.
7+
protected val propFilename: String = "/"
8+
}
9+
10+
object P extends T

0 commit comments

Comments
 (0)