File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -3430,9 +3430,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
34303430 def checkAmbiguousNamedTupleAssignment (tree : untpd.Tuple )(using Context ): Unit =
34313431 tree.trees match
34323432 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
3433+ val tmpCtx = ctx.fresh.setNewTyperState()
3434+ typedAssign(untpd.Assign (untpd.Ident (name), value), WildcardType )(using tmpCtx)
3435+ if ! tmpCtx.reporter.hasErrors then
3436+ // If there are no errors typing the above, then the named tuple is
3437+ // ambiguous and we issue a warning.
34363438 report.migrationWarning(AmbiguousNamedTupleAssignment (name, value), tree.srcPos)
34373439 case _ => ()
34383440
Original file line number Diff line number Diff line change 1+ -- [E203] Syntax Migration Warning: tests/warn/21681c.scala:5:2 --------------------------------------------------------
2+ 5 | (age = 29) // warn
3+ | ^^^^^^^^^^
4+ | Ambiguous syntax: this is interpreted as a named tuple with one element,
5+ | not as an assignment.
6+ |
7+ | To assign a value, use curly braces: `{age = 29}`.
Original file line number Diff line number Diff line change 1+ object Test :
2+ def age : Int = ???
3+ def age_= (x : Int ): Unit = ()
4+ age = 29
5+ (age = 29 ) // warn
You can’t perform that action at this time.
0 commit comments