Skip to content

Commit

Permalink
Do not store to non-existent fields in trait setters.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrd committed Apr 6, 2020
1 parent 454659a commit ae7bc0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,13 @@ object NameOps {
def setterName: TermName = name.exclude(FieldName) ++ str.SETTER_SUFFIX

def getterName: TermName =
name.exclude(FieldName).mapLast(n =>
if (n.endsWith(str.SETTER_SUFFIX)) n.take(n.length - str.SETTER_SUFFIX.length).asSimpleName
else n)
if name.is(TraitSetterName) then
val TraitSetterName(_, original) = name
original.getterName
else
name.exclude(FieldName).mapLast(n =>
if (n.endsWith(str.SETTER_SUFFIX)) n.take(n.length - str.SETTER_SUFFIX.length).asSimpleName
else n)

def fieldName: TermName =
if (name.isSetterName)
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Memoize.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SymUtils._
import Constants._
import ast.Trees._
import MegaPhase._
import NameKinds.TraitSetterName
import NameOps._
import Flags._
import Decorators._
Expand Down Expand Up @@ -114,7 +115,8 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase =>
EmptyTree
}

if (sym.is(Accessor, butNot = NoFieldNeeded)) {
if (sym.is(Accessor, butNot = NoFieldNeeded)
&& (!sym.name.is(TraitSetterName) || sym.getter.is(Accessor, butNot = NoFieldNeeded))) {
val field = sym.field.orElse(newField).asTerm

def adaptToField(tree: Tree): Tree =
Expand Down

0 comments on commit ae7bc0e

Please sign in to comment.