Repository navigation
Accept a standalone { } block, and report a block header with no { - #375
Merged
Merged
Conversation
Contributor
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Next included review available in 3 minutes. View limit details
|
jbearak
force-pushed
the
brace-diagnostics
branch
from
November 5, 2026 03:59
3864625 to
af96315
Compare
- A `{ ... }` block that starts a statement is a block with no prefix,
not OPEN_BRACE_ALONE. StataMP 18 runs one at the top level, in a
program, after another block, nested, in a loop, and under
`#delimit ;`. Its body is now parsed and printed.
- New MISSING_OPEN_BRACE (error): `if x` alone, `else if x` alone, and
`foreach`, `forvalues`, or `while` with no `{` at the end of the line
(or statement, under `#delimit ;`), even with a command after it.
Stata stops with "{ required" (r(100)).
- OPEN_BRACE_ALONE now means a `{` that starts the statement after a
header with no `{` (Stata stops at the header), after a bare `else`
or a prefix like `capture` (Stata runs the block on its own), or a
`{` after a command on its line (Stata passes it to the command).
- AST formatting leaves `{ di 1` and `quietly { di 1` as written:
Stata stops there (r(198)), and printing would move `di 1` onto a
line where it runs.
jbearak
force-pushed
the
brace-diagnostics
branch
from
November 5, 2026 04:05
af96315 to
bc754da
Compare
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.
Sight reported every standalone
{ … }block as OPEN_BRACE_ALONE at error level, but it's valid Stata. StataMP 18 runs one at the top level, in a program, after another block, nested, in a loop, and under#delimit ;. The parser also skipped the block's body, so the code inside it got spurious UNNECESSARY_INDENTATION hints. Sight also said nothing aboutif xwith no command and no{, which Stata rejects with "{ required" (r(100)).Now a
{that starts a statement is a block with no prefix. The parser reads its body, and both the pretty printer andparse --jsonalready supported a block with no prefix. A block header with no{gets a new error, MISSING_OPEN_BRACE.Behavior
if xalone andelse if xalone. Also forforeach,forvaluesorwhilewith no{at the end of the line (under#delimit ;, the statement), even with a command after it. All of these stop Stata with r(100), including under#delimit ;. Aftercapturethey set_rcto 100.{that starts the statement right after one that needed it:{(if 1, then{on the next line), where Stata stops at the header;else, or a prefix alone on its line such ascaptureorquietly, where Stata runs the block on its own: whatever theiffound, or without the prefix (an error in it isn't captured);{after a command on the same line (b {), which Stata passes to the command as an argument. The old recovery stays for this case; only the message changed.else(else, then a command on the next line) is valid Stata and isn't reported.docs/diagnostics.mddescribes both codes.Formatting
{ di 1andquietly { di 1as written. Stata stops at both with r(198), and printing would movedi 1onto its own line, where it runs.{, a{after a bareelse, andb {keep the file under source-preserving formatting.sight parse --jsonchanges (for do2r)The golden files don't change, because no fixture has these forms. For other files:
{ … }now appears instatementsaskind: "block"withprefixes: []and itsbody. Before, it wasn't instatementsat all, and its body was missing too.MISSING_OPEN_BRACE,severity: "error", with a range covering the header from its keyword to its last token.open brace must be on the same line as `if`; Stata stops with "{ required", and`else`or`capture`with "here the block runs…". Theb {case reads "open brace does not open a block here: Stata passes it to the command before it". The range is still the{token.{ di 1without a prefix now givesCODE_AFTER_OPEN_BRACE(warning) instead ofOPEN_BRACE_ALONE(error), the same asquietly { di 1already did.Proof:
tests/unit/brace-block-diagnostics.test.tsruns every form below throughDiagnosticsProvider(36 of 54 fail on main). The cases mirror StataMP 18 runs on each form. All four gates pass separately, including theparse --jsongolden test. A sweep of about 1,000 unique real.do/.adofiles found two new MISSING_OPEN_BRACE hits, both real (if (cond)with nothing after it), and otherwise the same brace diagnostics as main.StataMP 18 transcripts (abridged)
Not changed (reported separately)
quietly { local x 5 }followed by`x'still warns thatxis undefined. That also applies to standalone blocks. Theanalyzer-command-bodiesthread is handling it.{ diandquietly { diwith r(198). Only after a control-flow header (if 1 { di) does Stata ignore the code.Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved
Created with Claude Opus 5.5 in T3 Code (Claude Code harness), reviewed by gpt-6.1-sol in Codex.