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