Skip to content

Commit 44708ec

Browse files
committed
Try to type as an Assign
1 parent ca5f467 commit 44708ec

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,9 +3427,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
34273427
def checkAmbiguousNamedTuple(tree: untpd.Tuple)(using Context): Unit =
34283428
tree.trees match
34293429
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
3430+
if typedAssign(untpd.Assign(untpd.Ident(name), value), WildcardType) != EmptyTree then
34333431
report.migrationWarning(AmbiguousNamedTupleAssignment(name, value), tree.srcPos)
34343432
case _ =>
34353433

tests/warn/21681c.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E203] Syntax Migration Warning: tests/warn/21681c.scala:6:2 --------------------------------------------------------
2+
6 | (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}`.

tests/warn/21681c.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
object Test:
3+
def age: Int = ???
4+
def age_=(x: Int): Unit = ()
5+
age = 29
6+
(age = 29) // warn
7+

0 commit comments

Comments
 (0)