Parse dart files with the SDK version from the pubspec - #186
Open
gmpassos wants to merge 1 commit into
Open
Conversation
`getDartDirectivePackageNames` parsed every dart file with `FeatureSet.latestLanguageVersion()`, so syntax newer than the package's declared SDK constraint was silently accepted. `checkPackage` now resolves a `FeatureSet` from the `environment: sdk:` lower bound of the pubspec it already parsed, and passes it down to `getDartDirectivePackageNames`. Workspace sub-packages get their own feature set, since `checkPackage` recurses per sub-package. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JUxxy3wafsbkdCCRqmZEDd
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
getDartDirectivePackageNamesparsed every dart file withparseString's default feature set,FeatureSet.latestLanguageVersion(). Syntax newer than the package's declared SDK constraint was therefore accepted silently, even though the analyzer would reject it in the package it lives in.Change
checkPackageresolves aFeatureSetfrom theenvironment: sdk:lower bound of the pubspec it already parses (truncated tomajor.minor.0, since a language version has no patch component) and passes it down togetDartDirectivePackageNames:featureSetForPubspecfalls back toFeatureSet.latestLanguageVersion()when there is no SDK lower bound.sdk: 3.0.0) works too —VersionimplementsVersionRangewith itself as the lower bound.checkPackagealready recurses per sub-package.// @dart=x.yoverrides still apply:parseStringhands the feature set to the scanner asfeatureSetForOverriding.Behavior change
A file using syntax newer than its pubspec's SDK lower bound now hits the existing
ArgumentErrorpath ingetDartDirectivePackageNames, which prints the diagnostic and exits 1. Such code is genuinely invalid under language versioning, but it is a harder failure than before.Testing
dart analyze/dart formatclean.sealed class: withsdk: ">=2.19.0 <4.0.0"it now reportsexperiment_not_enabled: This requires the 'sealed-class' language feature to be enabled; withsdk: ^3.0.0it parses and validates normally.dart test: 84 passing. The 4 failures intest/executable_test.dartare pre-existing and reproduce identically on unmodifiedmaster(their fixtures need network access forpub get).🤖 Generated with Claude Code
https://claude.ai/code/session_01JUxxy3wafsbkdCCRqmZEDd