Skip to content

Commit b44adf7

Browse files
Merge pull request #5845 from dotty-staging/fix-#5036
Fix #5036: Add missing implementation for setters of Unit
2 parents 00551a7 + 5540913 commit b44adf7

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,12 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase =>
139139
} else if (sym.isSetter) {
140140
if (!sym.is(ParamAccessor)) { val Literal(Constant(())) = tree.rhs } // This is intended as an assertion
141141
field.setFlag(Mutable) // Necessary for vals mixed in from Scala2 traits
142-
if (isErasableBottomField(tree.vparamss.head.head.tpt.tpe.classSymbol)) tree
143-
else {
144-
val initializer = Assign(ref(field), adaptToField(ref(tree.vparamss.head.head.symbol)))
145-
val setterDef = cpy.DefDef(tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym)))
146-
removeAnnotations(sym)
147-
setterDef
148-
}
142+
val initializer =
143+
if (isErasableBottomField(tree.vparamss.head.head.tpt.tpe.classSymbol)) Literal(Constant(()))
144+
else Assign(ref(field), adaptToField(ref(tree.vparamss.head.head.symbol)))
145+
val setterDef = cpy.DefDef(tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym)))
146+
removeAnnotations(sym)
147+
setterDef
149148
}
150149
else tree // curiously, some accessors from Scala2 have ' ' suffixes. They count as
151150
// neither getters nor setters

tests/pos/i5036.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class i0(var i1: Unit)
2+
class i1(var i1: Null)
3+
class i3(var i1: Nothing)

0 commit comments

Comments
 (0)