From 3bea2ce30904a1656e37f02d5764f50c2b8d743c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 9 Mar 2018 16:49:36 +0100 Subject: [PATCH] Remove dead code in CapturedVars Only field can have an empty rhs and they are not captured in this way --- .../dotty/tools/dotc/transform/CapturedVars.scala | 5 +---- tests/pos/capturedVars2.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/pos/capturedVars2.scala diff --git a/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala b/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala index 55704e71ee3b..3e1977ed5e1a 100644 --- a/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala +++ b/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala @@ -111,10 +111,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase = def boxMethod(name: TermName): Tree = ref(vble.info.classSymbol.companionModule.info.member(name).symbol) cpy.ValDef(vdef)( - rhs = vdef.rhs match { - case EmptyTree => boxMethod(nme.zero).appliedToNone.withPos(vdef.pos) - case arg => boxMethod(nme.create).appliedTo(arg) - }, + rhs = boxMethod(nme.create).appliedTo(vdef.rhs), tpt = TypeTree(vble.info).withPos(vdef.tpt.pos)) } else vdef } diff --git a/tests/pos/capturedVars2.scala b/tests/pos/capturedVars2.scala new file mode 100644 index 000000000000..46ac28fdf4dd --- /dev/null +++ b/tests/pos/capturedVars2.scala @@ -0,0 +1,14 @@ +abstract class Test { + + var field: Int + val field2: Int + + def foo() = { + + var x: Int = 1 + + def inner() = { + x = x + 1 + field + field2 + } + } +}