Skip to content

Commit a7c8920

Browse files
Merge pull request #8080 from dotty-staging/fix-6987
Fix #6987: don't generate assignment for dropped fields
2 parents 031e6f2 + 3689650 commit a7c8920

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
212212
}
213213
splitStats(stats1)
214214
case Nil =>
215-
(Nil, Nil)
216215
}
217216
splitStats(tree.body)
218217

@@ -222,6 +221,10 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
222221
dropped += acc
223222
Nil
224223
}
224+
else if (!isRetained(acc.field)) { // It may happen for unit fields, tests/run/i6987.scala
225+
dropped += acc.field
226+
Nil
227+
}
225228
else {
226229
if (acc.hasAnnotation(defn.TransientParamAnnot))
227230
ctx.error(em"transient parameter $acc is retained as field in class ${acc.owner}", acc.sourcePos)

tests/run/i6987.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A(val u: Unit)
2+
3+
@main def Test = A(())

tests/run/i6987b.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
enum SingleCase {
2+
case TheCase1(u: Unit)
3+
}
4+
5+
case class TheCase2(u: Unit)
6+
7+
case class TheCase3(s: String, u: Unit)
8+
9+
class TheCase4(val u: Unit)
10+
11+
abstract class TheCase5(val u: Unit)
12+
13+
@main def Test =
14+
SingleCase.TheCase1(())
15+
TheCase2(())
16+
TheCase3("", ())
17+
TheCase4(())
18+
new TheCase5(()) {}

0 commit comments

Comments
 (0)