Only emit ternary :-spacing diagnostics when a : is present#624
Open
JohnCobbler wants to merge 1 commit into
Open
Only emit ternary :-spacing diagnostics when a : is present#624JohnCobbler wants to merge 1 commit into
:-spacing diagnostics when a : is present#624JohnCobbler wants to merge 1 commit into
Conversation
parse_cond reports "space required before/after `:` in `?` expression" unconditionally, but those checks assume a `:` was parsed. When the `:` is missing (e.g. `a ? b)`), the correct "`:` expected" diagnostic already fires, yet the spacing diagnostics still tell the user to space a `:` that is not there. Gate both spacing checks on a had_colon flag so they fire only when a `:` is actually present. Co-authored-by: Claude <noreply@anthropic.com>
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.
parse_condemits "space required before:in?expression" and"space required after
:in?expression" unconditionally, but thosechecks assume a
:is actually present. When the:is missing, parsing aternary like
a ? b)already reports the correct ":expected in?expression", yet the two spacing diagnostics still fire — so the user is told
to add whitespace around a
:that does not exist (#429).This gates both spacing diagnostics on the
:token being present, via ahad_colonflag computed once. The ":expected" path and the surroundingrecovery are unchanged; cases that do contain a
:(a ? b: c,a ? b :c,a ? b:c) still report the spacing errors as before.Adds a
parse_condtest for the no-:case:a ? b)parses to(? a b (error-t) (error))— a single(error-t)for the missing:,with no spurious spacing-error node.
Fixes #429
Disclosure: this pull request was written with the assistance of generative AI; all claims were verified against source, and human-reviewed.