Skip to content

Commit 24c3e7f

Browse files
committed
Add migration rewrite deprecated assignment syntax
1 parent 861beee commit 24c3e7f

File tree

9 files changed

+47
-0
lines changed

9 files changed

+47
-0
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

+1
Original file line numberDiff line numberDiff line change
@@ -3350,6 +3350,7 @@ final class DeprecatedAssignmentSyntax(key: Name, value: untpd.Tree)(using Conte
33503350
|not as an assignment.
33513351
|
33523352
|To assign a value, use curly braces: `{${key} = ${value}}`."""
3353+
+ Message.rewriteNotice("This", version = SourceVersion.`3.6-migration`)
33533354

33543355
override protected def explain(using Context): String = ""
33553356

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

+3
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
34423442
// If there are no errors typing the above, then the named tuple is
34433443
// ambiguous and we issue a warning.
34443444
report.migrationWarning(DeprecatedAssignmentSyntax(name, value), tree.srcPos)
3445+
if MigrationVersion.AmbiguousNamedTupleSyntax.needsPatch then
3446+
patch(tree.source, Span(tree.span.start, tree.span.start + 1), "{")
3447+
patch(tree.source, Span(tree.span.end - 1, tree.span.end), "}")
34453448
case _ => ()
34463449

34473450
/** Retrieve symbol attached to given tree */

compiler/test/dotty/tools/dotc/CompilationTests.scala

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CompilationTests {
8080
compileDir("tests/rewrites/annotation-named-pararamters", defaultOptions.and("-rewrite", "-source:3.6-migration")),
8181
compileFile("tests/rewrites/i21418.scala", unindentOptions.and("-rewrite", "-source:3.5-migration")),
8282
compileFile("tests/rewrites/infix-named-args.scala", defaultOptions.and("-rewrite", "-source:3.6-migration")),
83+
compileFile("tests/rewrites/ambigious-named-tuple-assignment.scala", defaultOptions.and("-rewrite", "-source:3.6-migration")),
8384
).checkRewrites()
8485
}
8586

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.language.experimental.namedTuples
2+
3+
object i21770:
4+
def f(g: Int => Unit) = g(0)
5+
var cache: Option[Int] = None
6+
f(i => {cache = Some(i)})
7+
8+
object i21861:
9+
var age: Int = 28
10+
{
11+
age = 29
12+
}
13+
14+
15+
object i21861c:
16+
def age: Int = ???
17+
def age_=(x: Int): Unit = ()
18+
age = 29
19+
{ age = 29 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.language.experimental.namedTuples
2+
3+
object i21770:
4+
def f(g: Int => Unit) = g(0)
5+
var cache: Option[Int] = None
6+
f(i => (cache = Some(i)))
7+
8+
object i21861:
9+
var age: Int = 28
10+
(
11+
age = 29
12+
)
13+
14+
15+
object i21861c:
16+
def age: Int = ???
17+
def age_=(x: Int): Unit = ()
18+
age = 29
19+
( age = 29 )

tests/warn/21681.check

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| not as an assignment.
66
|
77
| To assign a value, use curly braces: `{age = 29}`.
8+
| This can be rewritten automatically under -rewrite -source 3.6-migration.

tests/warn/21681b.check

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| not as an assignment.
66
|
77
| To assign a value, use curly braces: `{age = 29}`.
8+
| This can be rewritten automatically under -rewrite -source 3.6-migration.

tests/warn/21681c.check

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| not as an assignment.
66
|
77
| To assign a value, use curly braces: `{age = 29}`.
8+
| This can be rewritten automatically under -rewrite -source 3.6-migration.

tests/warn/21770.check

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| not as an assignment.
66
|
77
| To assign a value, use curly braces: `{cache = Some(i)}`.
8+
| This can be rewritten automatically under -rewrite -source 3.6-migration.

0 commit comments

Comments
 (0)