From e4d317fb92eb9e27bf79784985b7f33e56f1ae4c Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Fri, 5 May 2017 16:56:26 +0200 Subject: [PATCH 1/2] Fix #2375: Memoize should not generate static fields. They are not transformed by Getters phase, they keep the original name and never renamed. --- compiler/src/dotty/tools/dotc/transform/Memoize.scala | 1 + compiler/src/dotty/tools/dotc/transform/SymUtils.scala | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/Memoize.scala b/compiler/src/dotty/tools/dotc/transform/Memoize.scala index 8b5ceb0aadbb..605f784b602f 100644 --- a/compiler/src/dotty/tools/dotc/transform/Memoize.scala +++ b/compiler/src/dotty/tools/dotc/transform/Memoize.scala @@ -69,6 +69,7 @@ import Decorators._ val sym = tree.symbol def newField = { + assert(!sym.hasAnnotation(defn.ScalaStaticAnnot)) val fieldType = if (sym.isGetter) sym.info.resultType else /*sym.isSetter*/ sym.info.firstParamTypes.head diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index 4c07ca4c8c7b..e87368aeb6d2 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -97,8 +97,13 @@ class SymUtils(val self: Symbol) extends AnyVal { if (self.isSetter) self else accessorNamed(self.asTerm.name.setterName) - def field(implicit ctx: Context): Symbol = - self.owner.info.decl(self.asTerm.name.fieldName).suchThat(!_.is(Method)).symbol + def field(implicit ctx: Context): Symbol = { + val fieldName = if (self.hasAnnotation(defn.ScalaStaticAnnot)) { + self.name.asTermName.getterName + } else self.asTerm.name.fieldName + + self.owner.info.decl(fieldName).suchThat(!_.is(Method)).symbol + } def isField(implicit ctx: Context): Boolean = self.isTerm && !self.is(Method) From 9b91a2c013359b6fbb1b2b156587f8764a2aea58 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 6 May 2017 15:13:54 +0200 Subject: [PATCH 2/2] Polishing --- compiler/src/dotty/tools/dotc/transform/SymUtils.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index e87368aeb6d2..b6ae97450aae 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -98,10 +98,10 @@ class SymUtils(val self: Symbol) extends AnyVal { else accessorNamed(self.asTerm.name.setterName) def field(implicit ctx: Context): Symbol = { - val fieldName = if (self.hasAnnotation(defn.ScalaStaticAnnot)) { - self.name.asTermName.getterName - } else self.asTerm.name.fieldName - + val thisName = self.name.asTermName + val fieldName = + if (self.hasAnnotation(defn.ScalaStaticAnnot)) thisName.getterName + else thisName.fieldName self.owner.info.decl(fieldName).suchThat(!_.is(Method)).symbol }