Commit 8f00a51
authored
Always disallow assignments to constants (#57567)
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 edf1cd0 commit 8f00a51
2 files changed
+13
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
550 | | - | |
| 550 | + | |
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
557 | | - | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
558 | 563 | | |
559 | 564 | | |
560 | 565 | | |
| |||
1509 | 1514 | | |
1510 | 1515 | | |
1511 | 1516 | | |
1512 | | - | |
1513 | | - | |
1514 | | - | |
1515 | | - | |
1516 | | - | |
1517 | | - | |
1518 | | - | |
1519 | | - | |
1520 | | - | |
1521 | | - | |
1522 | 1517 | | |
1523 | 1518 | | |
1524 | 1519 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3973 | 3973 | | |
3974 | 3974 | | |
3975 | 3975 | | |
| 3976 | + | |
3976 | 3977 | | |
3977 | | - | |
| 3978 | + | |
| 3979 | + | |
| 3980 | + | |
| 3981 | + | |
| 3982 | + | |
3978 | 3983 | | |
3979 | 3984 | | |
3980 | 3985 | | |
| |||
0 commit comments