Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request fixes a StateError ("Bad state: No element") that occurred when calling matches() or matchAsPrefix() on glob patterns containing an empty option branch, such as {**/,}foo.dart. The fix ensures that SequenceNode.canMatchAbsolute and SequenceNode.canMatchRelative in pkgs/glob/lib/src/ast.dart safely handle empty node sequences. Additionally, a unit test has been added to verify this behavior, and the changelog has been updated. There are no review comments, so I have no feedback to provide.
4 tasks done
Contributor
Author
|
Friendly ping on this one. It's a small fix for the StateError on patterns with an empty option branch, and CI is green. Happy to adjust anything if someone has a moment to take a look. |
SequenceNode.canMatchAbsolute and canMatchRelative called nodes.first
without checking whether nodes was empty. An empty SequenceNode arises
from the empty branch of an options group, e.g. the pattern
'{**/,}foo.dart', whose second option has no nodes. Calling matches()
or matchAsPrefix() on such a pattern threw "Bad state: No element"
instead of matching normally.
Fixes dart-lang#2004
hkarmoush
force-pushed
the
glob-fix-empty-option-canmatchabsolute-2004
branch
from
November 13, 2026 07:38
f1c06ed to
a0b580a
Compare
This branch has not been deployed
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.
Summary
SequenceNode.canMatchAbsolute/canMatchRelativeinpkgs/glob/lib/src/ast.dartcallednodes.firstwithout checking for an empty node list, which throwsBad state: No elementfor any pattern with an empty option branch (e.g.{**/,}foo.dart).nodeslist, falling back to the base-class defaults (canMatchAbsolute = false,canMatchRelative = true), which correctly describe an empty sequence: it can only match an empty (relative) segment, never an absolute path.Test plan
pkgs/glob/test/match_test.dartreproducing the reported pattern ({**/,}foo.dart) and confirming it matches instead of throwing.dart test— all 145 tests passdart analyze— no issuesdart format --output=none --set-exit-if-changed .— cleanFixes #2004