Commit 6384f0b
committed
Always disallow assignments to constants
We have historically allowed the following without warning or error:
```
const x = 1
x = 1
```
As well as
```
const x = 1
x = 2
```
with a UB warning.
In 1.12, we made the second case error, as part of the general binding
partition changes, but did not touch the first case, because it did not
have the warning.
I think this made a reasonable amount of sense, because we essentially
treated constants as special kinds of mutable globals (to which assignment
happened to be UB).
However, in the 1.12+ design, constants and globals are quite sepearate
beasts, and I think it makes sense to extend the error to the egal case
also, even if it is technically more breaking.
In fact, I already thought that's what I did when I implemented the new
effect model for global assignment, causing #57566. I can't think of a
legitimate reason to keep this special case. For those who want to do
binding replacement, the `const` keyword is mandatory, so the assignment
is now literally always a semantic no-op or an error.
Fixes #57566.1 parent b0323ab commit 6384f0b
2 files changed
+13
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
545 | 545 | | |
546 | 546 | | |
547 | 547 | | |
548 | | - | |
| 548 | + | |
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
555 | | - | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
556 | 561 | | |
557 | 562 | | |
558 | 563 | | |
| |||
1449 | 1454 | | |
1450 | 1455 | | |
1451 | 1456 | | |
1452 | | - | |
1453 | | - | |
1454 | | - | |
1455 | | - | |
1456 | | - | |
1457 | | - | |
1458 | | - | |
1459 | | - | |
1460 | | - | |
1461 | | - | |
1462 | 1457 | | |
1463 | 1458 | | |
1464 | 1459 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3969 | 3969 | | |
3970 | 3970 | | |
3971 | 3971 | | |
| 3972 | + | |
3972 | 3973 | | |
3973 | | - | |
| 3974 | + | |
| 3975 | + | |
| 3976 | + | |
| 3977 | + | |
| 3978 | + | |
3974 | 3979 | | |
3975 | 3980 | | |
3976 | 3981 | | |
| |||
0 commit comments