Parse files with the language version the package declares - #187
Open
maxim-sysoev wants to merge 1 commit into
Open
Parse files with the language version the package declares#187maxim-sysoev wants to merge 1 commit into
maxim-sysoev wants to merge 1 commit into
Conversation
parseString falls back to FeatureSet.latestLanguageVersion() when no feature set is given. On analyzer 13 that version is unreleased and rejects a `final` modifier on formal parameters, so validation aborts with "Error parsing" on code the SDK analyzer accepts. Packages using freezed hit this without writing `final` themselves: the generator emits it for parameters with default values. Derive the feature set from the package's SDK constraint, the same way the analyzer determines a package's language version, and fall back to the latest version when the constraint is missing or unbounded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
getDartDirectivePackageNamescallsparseStringwithout a feature set, so it falls back toFeatureSet.latestLanguageVersion()— the newest language version the bundled analyzer knows about. With analyzer 13 that version is unreleased, and it rejects thefinalmodifier on formal parameters:The run aborts with exit code 1 before a single dependency is checked, on code the SDK analyzer accepts without complaint.
The behaviour arrived with
5.0.6(Allow up to analyzer 13). The parsing code itself is byte-identical to5.0.5; only the resolved analyzer changed —5.0.5resolves analyzer 12.1.0 and passes,5.0.6resolves analyzer 13.3.0 and fails.Pinning the language version explicitly confirms the cause — the same snippet parses cleanly under every released version:
latestLanguageVersion()Why it hits projects that never write
finalon a parameterfreezedemits the modifier itself. A declaration containing nofinalat all generates a constructor that does, so every generated file in afreezedproject fails to parse. In our monorepo five of twelve packages turned red overnight with no source change — CI installs the tool unpinned, so5.0.6was picked up automatically.Excluding generated files via
dart_dependency_validator.yamlremoves the parse errors but defeats the check: dependencies used only from generated code are then reported as unused, which has to be silenced in turn.Fix
Derive the feature set from the package's SDK constraint — the same way the analyzer determines a package's language version — and fall back to the previous behaviour when the constraint is missing or unbounded. The feature set is computed once per package and passed into the parse; the parameter is optional, so the public function stays source-compatible.
Tests
Adds a regression test to
executable_test.dart: a project whose library usesfinalon both a positional and a named parameter now validates cleanly. The test fails onmasterand passes with this change.The rest of the suite is unchanged: 4 tests fail both with and without this change on my machine (
+84 -4either way), so they look unrelated to it.Suppressing diagnostics with
throwIfDiagnostics: falsewas considered and rejected: it would also hide genuinely malformed files. With this change a truly broken file still reportsexpected_tokendiagnostics as before.