Commit a9f127d
[analyzer] Rewrite
Previously, this class was based on `AstComparator` (and was the sole
user of `AstComparator`). The new implementation is based on
`AstNodeImpl.namedChildEntities`. In a follow-up CL I'll remove
`AstComparator`, which should make future modifications to the
analyzer AST classes just a little bit easier and less error-prone.
I've gone ahead and made some improvements to `ResultComparator` in
the process:
- I've improved the failure messages when there is a token mismatch,
so that the token details (synthetic/non-synthetic, token type,
lexeme, and length) are shown, as well as the path to the mismatched
token in the AST.
- I've improved the syntax for showing the path to the
mismatch. Previously all that was shown was the types of the
ancestor AST nodes, which was useful but didn't give complete
information. Now the types are shown as well as the getter names and
indices necessary to reach the mismatch. For example, a mismatch
between `class X {}` and `class C {}` is now shown with the path
`((root as CompilationUnit).declarations[0] as
ClassDeclaration).name`.
- I've tightened up the rules for token matching. An "actual" token
that is synthetic no longer matches just any old "expected" token;
the expected token must be `_s_` for a synthetic identifier, or an
empty string for a synthetic string. This required some minor fixes
to be made to `try_statement_test.dart`.
- Documentation comments are now fully checked; previously only
comment references were checked.
Note that the tests `ModifiersTest.test_classDeclaration_static` and
`MissingCodeTest.test_stringInterpolation_unclosed` now pass. These
tests exercise parser recovery scenarios where a token is either
ignored or synthetically inserted at the very beginning or end of a
compilation unit. These tests were failing under the old
`AstComparator`-based implementation of `ResultComparator`, because in
addition to recursively comparing the AST structures of a compilation
unit, `AstComparator` compares `CompilationUnit.beginToken` and
`CompilationUnit.endToken`. These fields store the true starting and
ending tokens of the compilation unit (not the results of parser error
recovery), so as a result, the old `AstComparator`-based
implementation of `ResultComparator` was reporting that parser error
recovery had failed when it had in fact succeeded. The new
implementation of `ResultComparator` only compares the AST structures,
so it correctly concludes that parser error recovery has succeeded.
Change-Id: Ifac2065b823e604e07a64500eb2b6b2be125802d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419521
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Paul Berry <[email protected]>ResultComparator.1 parent d7e0c3c commit a9f127d
File tree
5 files changed
+386
-120
lines changed- pkg/analyzer/test/src/fasta/recovery
- partial_code
5 files changed
+386
-120
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | 166 | | |
168 | | - | |
169 | | - | |
170 | 167 | | |
171 | 168 | | |
172 | 169 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
453 | 453 | | |
454 | 454 | | |
455 | 455 | | |
456 | | - | |
457 | 456 | | |
458 | 457 | | |
459 | 458 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
0 commit comments