Skip to content

Commit 9102aac

Browse files
Backport "Tweak parameter accessor scheme" to LTS (#20927)
Backports #19719 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents e232d65 + 0127f13 commit 9102aac

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
112112
* This info is used in phase ParamForwarding
113113
*/
114114
private def forwardParamAccessors(impl: Template)(using Context): Unit = impl.parents match
115-
case superCall @ Apply(fn, superArgs) :: _ if superArgs.nonEmpty =>
115+
case superCall @ Apply(fn, superArgs) :: _
116+
if superArgs.nonEmpty && fn.symbol.isPrimaryConstructor =>
116117
fn.tpe.widen match
117118
case MethodType(superParamNames) =>
118119
for case stat: ValDef <- impl.body do

tests/run/i19711.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Foo(val s: Any):
2+
def this(s: String) =
3+
this(0)
4+
class Bar(s: String) extends Foo(s):
5+
def foo = s
6+
7+
class Foo2(val s: Any)
8+
class Bar2(s: String) extends Foo2(s):
9+
def foo = s
10+
11+
case class Config(_config: String)
12+
13+
abstract class Foo3(val config: Config) {
14+
def this(config: String) = {
15+
this(Config(config))
16+
}
17+
}
18+
19+
class Bar3(config: String) extends Foo3(config) {
20+
def foo(): Unit = {
21+
config.getClass()
22+
}
23+
}
24+
25+
26+
@main def Test =
27+
Bar("").foo
28+
Bar2("").foo
29+
Bar3("").foo()

0 commit comments

Comments
 (0)