Skip to content

Only emit ternary :-spacing diagnostics when a : is present#624

Open
JohnCobbler wants to merge 1 commit into
JuliaLang:mainfrom
JohnCobbler:fix/429-ternary-colon-diagnostics
Open

Only emit ternary :-spacing diagnostics when a : is present#624
JohnCobbler wants to merge 1 commit into
JuliaLang:mainfrom
JohnCobbler:fix/429-ternary-colon-diagnostics

Conversation

@JohnCobbler

Copy link
Copy Markdown

parse_cond emits "space required before : in ? expression" and
"space required after : in ? expression" unconditionally, but those
checks assume a : is actually present. When the : is missing, parsing a
ternary 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 a
had_colon flag computed once. The ": expected" path and the surrounding
recovery 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_cond test 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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error message for ternary assumes : was present.

1 participant