Commit a42244f
Flow analysis: begin tracking non-promotion reasons.
This CL implements the core flow analysis infrastructure for tracking
reasons why an expression was not promoted. It supports the following
reasons:
- Expression was a property access
- Expression has been written to since it was promoted
I expect to add support for other non-promotion reasons in the future,
for example:
- `this` cannot be promoted
- Expression has been write captured
- Expression was a reference to a static field or top level variable
These non-promotion reasons are plumbed through to the CFE and
analyzer for the purpose of making errors easier for the user to
understand. For example, given the following code:
class C {
int? i;
f() {
if (i == null) return;
print(i.isEven);
}
}
The front end now prints:
../../tmp/test.dart:5:13: Error: Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
Try accessing using ?. instead.
print(i.isEven);
^^^^^^
Context: 'i' refers to a property so it could not be promoted.
Much work still needs to be done to round out this feature, for example:
- Currently the analyzer only shows the new "why not promoted"
messages when the "--verbose" flag is specified; this means the
feature is unlikely to be noticed by users.
- Currently the analyzer doesn't show a "why not promoted" message
when the non-promotion reason is that the expression is a property
access.
- We need one or more web pages explaining non-promotion reasons in
more detail so that the error messages can contain pointers to them.
- The analyzer and front end currently only show non-promotion reasons
for expressions of the form `x.y` where `x` fails to be promoted to
non-nullable. There are many other scenarios that should be
handled.
Change-Id: I0a12df74d0fc6274dfb3cb555abea81a75884231
Bug: #38773
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181741
Commit-Queue: Paul Berry <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>1 parent 91be638 commit a42244f
File tree
39 files changed
+1676
-177
lines changed- .dart_tool
- pkg
- analyzer
- lib
- error
- src
- dart/resolver
- error
- generated
- test
- id_tests
- src
- lint
- workspace
- tool
- front_end
- lib/src/fasta
- kernel
- type_inference
- test
- id_tests
- tool
- nnbd_migration/lib/src
- tools
39 files changed
+1676
-177
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
58 | 63 | | |
59 | 64 | | |
60 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
Lines changed: 523 additions & 82 deletions
Large diffs are not rendered by default.
Lines changed: 51 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4032 | 4032 | | |
4033 | 4033 | | |
4034 | 4034 | | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
| 4042 | + | |
| 4043 | + | |
| 4044 | + | |
| 4045 | + | |
| 4046 | + | |
| 4047 | + | |
| 4048 | + | |
| 4049 | + | |
| 4050 | + | |
| 4051 | + | |
| 4052 | + | |
| 4053 | + | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
| 4057 | + | |
4035 | 4058 | | |
4036 | 4059 | | |
4037 | 4060 | | |
| |||
9620 | 9643 | | |
9621 | 9644 | | |
9622 | 9645 | | |
| 9646 | + | |
| 9647 | + | |
| 9648 | + | |
| 9649 | + | |
| 9650 | + | |
| 9651 | + | |
| 9652 | + | |
| 9653 | + | |
| 9654 | + | |
| 9655 | + | |
| 9656 | + | |
| 9657 | + | |
| 9658 | + | |
| 9659 | + | |
| 9660 | + | |
| 9661 | + | |
| 9662 | + | |
| 9663 | + | |
| 9664 | + | |
| 9665 | + | |
| 9666 | + | |
| 9667 | + | |
| 9668 | + | |
| 9669 | + | |
| 9670 | + | |
| 9671 | + | |
| 9672 | + | |
| 9673 | + | |
9623 | 9674 | | |
9624 | 9675 | | |
9625 | 9676 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
Lines changed: 136 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
157 | 162 | | |
158 | 163 | | |
159 | 164 | | |
| |||
273 | 278 | | |
274 | 279 | | |
275 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
276 | 285 | | |
277 | 286 | | |
278 | 287 | | |
279 | 288 | | |
280 | 289 | | |
281 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
282 | 299 | | |
283 | 300 | | |
284 | 301 | | |
| |||
311 | 328 | | |
312 | 329 | | |
313 | 330 | | |
| 331 | + | |
314 | 332 | | |
315 | 333 | | |
| 334 | + | |
316 | 335 | | |
317 | 336 | | |
318 | 337 | | |
| |||
347 | 366 | | |
348 | 367 | | |
349 | 368 | | |
| 369 | + | |
350 | 370 | | |
351 | 371 | | |
352 | 372 | | |
353 | 373 | | |
354 | 374 | | |
355 | 375 | | |
356 | 376 | | |
| 377 | + | |
357 | 378 | | |
358 | 379 | | |
359 | 380 | | |
| |||
364 | 385 | | |
365 | 386 | | |
366 | 387 | | |
| 388 | + | |
| 389 | + | |
367 | 390 | | |
368 | 391 | | |
369 | 392 | | |
| |||
410 | 433 | | |
411 | 434 | | |
412 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
413 | 439 | | |
414 | 440 | | |
415 | 441 | | |
| |||
597 | 623 | | |
598 | 624 | | |
599 | 625 | | |
| 626 | + | |
| 627 | + | |
600 | 628 | | |
601 | 629 | | |
602 | 630 | | |
603 | 631 | | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
604 | 642 | | |
605 | 643 | | |
606 | | - | |
607 | | - | |
608 | | - | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
609 | 650 | | |
610 | 651 | | |
611 | 652 | | |
| |||
1424 | 1465 | | |
1425 | 1466 | | |
1426 | 1467 | | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
1427 | 1491 | | |
1428 | 1492 | | |
1429 | 1493 | | |
| |||
1481 | 1545 | | |
1482 | 1546 | | |
1483 | 1547 | | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
1484 | 1585 | | |
1485 | 1586 | | |
1486 | 1587 | | |
| |||
1622 | 1723 | | |
1623 | 1724 | | |
1624 | 1725 | | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
1625 | 1757 | | |
1626 | 1758 | | |
1627 | 1759 | | |
| |||
1681 | 1813 | | |
1682 | 1814 | | |
1683 | 1815 | | |
1684 | | - | |
| 1816 | + | |
1685 | 1817 | | |
1686 | 1818 | | |
1687 | 1819 | | |
| |||
0 commit comments