Skip to content

Commit e02582b

Browse files
committed
Allow user-defined setters as targets of becomes in tpd
1 parent cb8ac79 commit e02582b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,19 +839,23 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
839839
tree.select(defn.Boolean_||).appliedTo(that)
840840

841841
/** The translation of `tree = rhs`.
842-
* This is either the tree as an assignment, to a setter call.
842+
* This is either the tree as an assignment, or a setter call.
843843
*/
844-
def becomes(rhs: Tree)(implicit ctx: Context): Tree =
845-
if (tree.symbol is Method) {
846-
val setter = tree.symbol.setter
847-
assert(setter.exists, tree.symbol.showLocated)
844+
def becomes(rhs: Tree)(implicit ctx: Context): Tree = {
845+
val sym = tree.symbol
846+
if (sym is Method) {
847+
val setter = sym.setter.orElse {
848+
assert(sym.name.isSetterName && sym.info.firstParamTypes.nonEmpty)
849+
sym
850+
}
848851
val qual = tree match {
849852
case id: Ident => desugarIdentPrefix(id)
850853
case Select(qual, _) => qual
851854
}
852855
qual.select(setter).appliedTo(rhs)
853856
}
854857
else Assign(tree, rhs)
858+
}
855859

856860
/** A synthetic select with that will be turned into an outer path by ExplicitOuter.
857861
* @param levels How many outer levels to select

0 commit comments

Comments
 (0)