Skip to content

Commit

Permalink
Try to type as an Assign
Browse files Browse the repository at this point in the history
  • Loading branch information
mbovel committed Oct 21, 2024
1 parent ca5f467 commit 44708ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3427,9 +3427,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
def checkAmbiguousNamedTuple(tree: untpd.Tuple)(using Context): Unit =
tree.trees match
case List(NamedArg(name, value)) =>
val typedName = typedIdent(untpd.Ident(name), WildcardType)
val sym = typedName.symbol
if sym.exists && (sym.is(Flags.Mutable) || sym.setter.exists) then
if typedAssign(untpd.Assign(untpd.Ident(name), value), WildcardType) != EmptyTree then
report.migrationWarning(AmbiguousNamedTupleAssignment(name, value), tree.srcPos)
case _ =>

Expand Down
7 changes: 7 additions & 0 deletions tests/warn/21681c.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E203] Syntax Migration Warning: tests/warn/21681c.scala:6:2 --------------------------------------------------------
6 | (age = 29) // warn
| ^^^^^^^^^^
| Ambiguous syntax: this is interpreted as a named tuple with one element,
| not as an assignment.
|
| To assign a value, use curly braces: `{age = 29}`.
7 changes: 7 additions & 0 deletions tests/warn/21681c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

object Test:
def age: Int = ???
def age_=(x: Int): Unit = ()
age = 29
(age = 29) // warn

0 comments on commit 44708ec

Please sign in to comment.