Skip to content

Commit 266a696

Browse files
committed
Allow user-defined setters as targets of becomes in tpd
1 parent 5a42cfa commit 266a696

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
@@ -836,19 +836,23 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
836836
tree.select(defn.Boolean_||).appliedTo(that)
837837

838838
/** The translation of `tree = rhs`.
839-
* This is either the tree as an assignment, to a setter call.
839+
* This is either the tree as an assignment, or a setter call.
840840
*/
841-
def becomes(rhs: Tree)(implicit ctx: Context): Tree =
842-
if (tree.symbol is Method) {
843-
val setter = tree.symbol.setter
844-
assert(setter.exists, tree.symbol.showLocated)
841+
def becomes(rhs: Tree)(implicit ctx: Context): Tree = {
842+
val sym = tree.symbol
843+
if (sym is Method) {
844+
val setter = sym.setter.orElse {
845+
assert(sym.name.isSetterName && sym.info.firstParamTypes.nonEmpty)
846+
sym
847+
}
845848
val qual = tree match {
846849
case id: Ident => desugarIdentPrefix(id)
847850
case Select(qual, _) => qual
848851
}
849852
qual.select(setter).appliedTo(rhs)
850853
}
851854
else Assign(tree, rhs)
855+
}
852856

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

0 commit comments

Comments
 (0)