Skip to content

Commit e1bfa81

Browse files
mbovelnicolasstuckibracevac
committed
Move AmbiguousNamedTupleAssignment check to Typer
Co-Authored-By: Nicolas Stucki <[email protected]> Co-Authored-By: Oliver Bračevac <[email protected]>
1 parent e4c42ea commit e1bfa81

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,6 @@ object desugar {
16391639
if ctx.mode.is(Mode.Type) then
16401640
AppliedTypeTree(ref(defn.NamedTupleTypeRef), namesTuple :: tup :: Nil)
16411641
else
1642-
if names.length == 1 && ctx.scope.lookup(names.head).is(Flags.Mutable) then
1643-
report.migrationWarning(AmbiguousNamedTupleAssignment(names.head, elemValues.head), tree.srcPos)
16441642
Apply(
16451643
Apply(
16461644
TypeApply(

tests/pos/21681b.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def test1() =
2+
class Person:
3+
def age: Int = ???
4+
def age_=(x: Int): Unit = ???
5+
6+
val person = Person()
7+
8+
(person.age = 29) // no warn (interpreted as `person.age_=(29)`)
9+
10+
def test2() =
11+
class Person:
12+
var age: Int = 28
13+
14+
val person = Person()
15+
16+
(person.age = 29) // no warn (interpreted as `person.age_=(29)`)
17+

tests/warn/21681b.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/21681b.scala:4:2 --------------------------------------------------------
2+
4 | (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/21681b.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
object Test:
3+
var age: Int = 28
4+
(age = 29) // warn
5+

0 commit comments

Comments
 (0)