Skip to content

Commit 84590eb

Browse files
committed
Merge pull request #800 from dotty-staging/paramForwarding-comment
ParamForwarding #783: answer my own question.
2 parents 6bb6210 + 8863819 commit 84590eb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/dotty/tools/dotc/transform/ParamForwarding.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
3333
case _ => (Nil, Nil)
3434
}
3535
def inheritedAccessor(sym: Symbol): Symbol = {
36+
/**
37+
* Dmitry: having it have the same name is needed to maintain correctness in presence of subclassing
38+
* if you would use parent param-name `a` to implement param-field `b`
39+
* overriding field `b` will actually override field `a`, that is wrong!
40+
*
41+
* class A(val s: Int);
42+
* class B(val b: Int) extends A(b)
43+
* class C extends A(2) {
44+
* def s = 3
45+
* assert(this.b == 2)
46+
* }
47+
*/
3648
val candidate = sym.owner.asClass.superClass
3749
.info.decl(sym.name).suchThat(_ is (ParamAccessor, butNot = Mutable)).symbol
3850
if (candidate.isAccessibleFrom(currentClass.thisType, superAccess = true)) candidate

0 commit comments

Comments
 (0)