Skip to content

Commit 3bea2ce

Browse files
committed
Remove dead code in CapturedVars
Only field can have an empty rhs and they are not captured in this way
1 parent 0353e64 commit 3bea2ce

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
111111
def boxMethod(name: TermName): Tree =
112112
ref(vble.info.classSymbol.companionModule.info.member(name).symbol)
113113
cpy.ValDef(vdef)(
114-
rhs = vdef.rhs match {
115-
case EmptyTree => boxMethod(nme.zero).appliedToNone.withPos(vdef.pos)
116-
case arg => boxMethod(nme.create).appliedTo(arg)
117-
},
114+
rhs = boxMethod(nme.create).appliedTo(vdef.rhs),
118115
tpt = TypeTree(vble.info).withPos(vdef.tpt.pos))
119116
} else vdef
120117
}

tests/pos/capturedVars2.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
abstract class Test {
2+
3+
var field: Int
4+
val field2: Int
5+
6+
def foo() = {
7+
8+
var x: Int = 1
9+
10+
def inner() = {
11+
x = x + 1 + field + field2
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)