Skip to content

Commit 385178d

Browse files
authored
Merge pull request #2377 from dotty-staging/fix-static-fields
Fix #2375: Memoize should not generate static fields.
2 parents 1ab7641 + 9b91a2c commit 385178d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import Decorators._
6969
val sym = tree.symbol
7070

7171
def newField = {
72+
assert(!sym.hasAnnotation(defn.ScalaStaticAnnot))
7273
val fieldType =
7374
if (sym.isGetter) sym.info.resultType
7475
else /*sym.isSetter*/ sym.info.firstParamTypes.head

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ class SymUtils(val self: Symbol) extends AnyVal {
9797
if (self.isSetter) self
9898
else accessorNamed(self.asTerm.name.setterName)
9999

100-
def field(implicit ctx: Context): Symbol =
101-
self.owner.info.decl(self.asTerm.name.fieldName).suchThat(!_.is(Method)).symbol
100+
def field(implicit ctx: Context): Symbol = {
101+
val thisName = self.name.asTermName
102+
val fieldName =
103+
if (self.hasAnnotation(defn.ScalaStaticAnnot)) thisName.getterName
104+
else thisName.fieldName
105+
self.owner.info.decl(fieldName).suchThat(!_.is(Method)).symbol
106+
}
102107

103108
def isField(implicit ctx: Context): Boolean =
104109
self.isTerm && !self.is(Method)

0 commit comments

Comments
 (0)