@@ -3395,6 +3395,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3395
3395
/** Translate tuples of all arities */
3396
3396
def typedTuple (tree : untpd.Tuple , pt : Type )(using Context ): Tree =
3397
3397
val tree1 = desugar.tuple(tree, pt)
3398
+ checkAmbiguousNamedTupleAssignment(tree)
3398
3399
if tree1 ne tree then typed(tree1, pt)
3399
3400
else
3400
3401
val arity = tree.trees.length
@@ -3420,6 +3421,18 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3420
3421
val resTpe = TypeOps .nestedPairs(elemTpes)
3421
3422
app1.cast(resTpe)
3422
3423
3424
+ /** Checks if `tree` is a named tuple with one element that could be
3425
+ * interpreted as an assignment, such as `(x = 1)`. If so, issues a warning.
3426
+ */
3427
+ def checkAmbiguousNamedTupleAssignment (tree : untpd.Tuple )(using Context ): Unit =
3428
+ tree.trees match
3429
+ case List (NamedArg (name, value)) =>
3430
+ val typedName = typedIdent(untpd.Ident (name), WildcardType )
3431
+ val sym = typedName.symbol
3432
+ if sym.exists && (sym.is(Flags .Mutable ) || sym.setter.exists) then
3433
+ report.migrationWarning(AmbiguousNamedTupleAssignment (name, value), tree.srcPos)
3434
+ case _ => ()
3435
+
3423
3436
/** Retrieve symbol attached to given tree */
3424
3437
protected def retrieveSym (tree : untpd.Tree )(using Context ): Symbol = tree.removeAttachment(SymOfTree ) match {
3425
3438
case Some (sym) =>
0 commit comments