CQ. Move constructor body diagnostics into ErrorVerifier

Centralize diagnostics for illegal constructor/method bodies in
ErrorVerifier instead of reporting them from the AST builder and Fasta
error conversion.

This consolidates several overlapping checks and fixes inconsistent
error locations (for example, reporting at `external`/`const` instead of
at `{`/`=>`).

Key changes:
- Remove constructor-body validation from AstBuilder (const bodies, const
  factories) and stop converting the corresponding Fasta codes to analyzer
  diagnostics to avoid duplicate reporting.
- Add a single verifier entry point that validates whether a body is allowed
  based on:
  - factory vs generative
  - const vs non-const
  - external vs non-external
  - redirecting vs non-redirecting
- Reuse the same validation for both regular constructors and primary
  constructors, and report at the body token for stable source ranges.
- Add a shared check for `external` functions/methods with block or expression
  bodies, and apply it consistently to top-level functions and class members.
- Align expectation files to the new, body-based error ranges and remove
  formatter-crash classification where the new reporting no longer triggers it.

Change-Id: Ie91ea08a7b5505d3e6443b12317c45359bac1c2d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477780
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2026-02-03 11:38:23 -08:00
committed by Commit Queue
parent 0f230f3262
commit 51003df5c3
12 changed files with 480 additions and 79 deletions
+4 -2
View File
@@ -70,14 +70,16 @@ class Foo {
}
external int t06(int i) { return 1; }
// [error column 1, length 8]
// ^
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_METHOD_WITH_BODY
// [error column 1, length 8]
// [cfe] An external or native method can't have a body.
// ^
// [cfe] An external or native method can't have a body.
external int t07(int i) => i + 1;
// [error column 1, length 8]
// ^^
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_METHOD_WITH_BODY
// [error column 1, length 8]
// [cfe] An external or native method can't have a body.
// ^
// [cfe] An external or native method can't have a body.