Skip to content

Fix ParamForwarder under non-separate compilation #2116

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

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
val candidate = sym.owner.asClass.superClass
.info.decl(sym.name).suchThat(_ is (ParamAccessor, butNot = Mutable)).symbol
if (candidate.isAccessibleFrom(currentClass.thisType, superAccess = true)) candidate
else if (candidate is Method) inheritedAccessor(candidate)
else if (candidate.exists) inheritedAccessor(candidate)
else NoSymbol
}
def forwardParamAccessor(stat: Tree): Tree = {
Expand Down
2 changes: 1 addition & 1 deletion tests/run/paramForwarding.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ NonVal:
X:
private final int X.theValue$$local
Y:
private final int Y.theValue$$local

4 changes: 2 additions & 2 deletions tests/run/paramForwarding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class NonVal(theValue: Int) extends A(theValue) {
// X.theValue() which overrides A.theValue()
class X(override val theValue: Int) extends NonVal(0)

// Y contains a field Y.theValue$$local accessible using the getter
// Y.theValue() which overrides A.theValue()
// Y does not contains a field Y.theValue$$local, it contains
// a getter Y.theValue() which only calls super.theValue()
class Y(override val theValue: Int) extends NonVal(theValue)


Expand Down
9 changes: 7 additions & 2 deletions tests/run/paramForwarding_separate/A_1.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class A(val member: Int)
class A(val member: Int) {
def getAMember = member
}

class SubA(member: Int) extends A(member) {
def getSubAMember = member
}

class SubA(member: Int) extends A(member)
4 changes: 3 additions & 1 deletion tests/run/paramForwarding_separate/B_2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class B(member: Int) extends SubA(member)
class B(member: Int) extends SubA(member) {
def getMember = member
}

object Test {
def printFields(cls: Class[_]) =
Expand Down
6 changes: 6 additions & 0 deletions tests/run/paramForwarding_together.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Fields in A:
private final int A.member$$local
# Fields in SubA:

# Fields in B:

29 changes: 29 additions & 0 deletions tests/run/paramForwarding_together.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class A(val member: Int) {
def getAMember = member
}

class SubA(member: Int) extends A(member) {
def getSubAMember = member
}

class B(member: Int) extends SubA(member) {
def getBMember = member
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not yet convinced this fixes it. Can you also add test cases where A, SubA, and B appear in different orders? Like: B, SubA, A, for instance?

Copy link
Member Author

@smarter smarter Mar 17, 2017

Choose a reason for hiding this comment

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

You mean, order of declaration in the file?

object Test {
def printFields(cls: Class[_]) =
println(cls.getDeclaredFields.map(_.toString).sorted.deep.mkString("\n"))

def main(args: Array[String]): Unit = {
val a = new A(10)
val subA = new SubA(11)
val b = new B(12)

println("# Fields in A:")
printFields(classOf[A])
println("# Fields in SubA:")
printFields(classOf[SubA])
println("# Fields in B:")
printFields(classOf[B])
}
}
6 changes: 6 additions & 0 deletions tests/run/paramForwarding_together_b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Fields in A:
private final int A.member$$local
# Fields in SubA:

# Fields in B:

30 changes: 30 additions & 0 deletions tests/run/paramForwarding_together_b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class B(member: Int) extends SubA(member) {
def getBMember = member
}

class SubA(member: Int) extends A(member) {
def getSubAMember = member
}

class A(val member: Int) {
def getAMember = member
}


object Test {
def printFields(cls: Class[_]) =
println(cls.getDeclaredFields.map(_.toString).sorted.deep.mkString("\n"))

def main(args: Array[String]): Unit = {
val a = new A(10)
val subA = new SubA(11)
val b = new B(12)

println("# Fields in A:")
printFields(classOf[A])
println("# Fields in SubA:")
printFields(classOf[SubA])
println("# Fields in B:")
printFields(classOf[B])
}
}