fix(semantic): attribute format!/print! bracket errors to the right macro - #10222
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR SummaryLow Risk Overview A shared Diagnostic snapshots were updated: wrong-bracket messages use the outer macro name, and the missing format-string case for empty Reviewed by Cursor Bugbot for commit f46890d. Bugbot is set up for automated code reviews on this repo. Configure here. |
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on orizi and TomerStarkware).
crates/cairo-lang-semantic/src/inline_macros/print.rs line 105 at r1 (raw file):
)); }; let ast::WrappedArgList::ParenthesizedArgList(args) = syntax.arguments(db) else {
DRY
2ecc736 to
d511f21
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi made 1 comment.
Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on eytan-starkware and TomerStarkware).
crates/cairo-lang-semantic/src/inline_macros/print.rs line 105 at r1 (raw file):
Previously, eytan-starkware wrote…
DRY
Done.
…acro
`format!`/`print!`/`println!` forwarded the user's wrapping brackets into the
synthesized inner `write!`/`writeln!` call. Since `write!` accepts only
parentheses, `format!{...}`, `print![...]` etc. failed with "Macro `write` does
not support this bracket type" — naming a macro the user never wrote.
Emit the synthesized inner call with parentheses unconditionally (it is
generated code), and validate the bracket at the `format!`/`print!` site like
`write!` does, so the diagnostic names the actual macro and points at the user's
bracket. The parens-only rule is unchanged, keeping the write/format/print
family consistent.
d511f21 to
f46890d
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware reviewed 4 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Summary
The
format!,print!, andprintln!macros now require parentheses as their bracket type. Previously, these macros forwarded whatever bracket type was used (e.g.,format![...]) directly into the generatedwrite!/writeln!call, which caused the "unsupported bracket type" diagnostic to incorrectly referencewriteorwritelninstead of the actual macro being invoked. Now, non-parenthesis brackets are rejected early with a diagnostic naming the correct macro, and the generated code always uses parentheses for the innerwrite!/writeln!call.Additionally, the "no params" diagnostic span for
format!()andprint!()was corrected to point at the entire macro invocation rather than just the opening bracket.Type of change
Please check one:
Why is this change needed?
When a user wrote
format![...]orprint![...], the diagnostic reported that macrowritedoes not support this bracket type, which was confusing because the user never invokedwritedirectly. The root cause was that the bracket tokens were forwarded verbatim into the generatedwrite!expansion, so the error surfaced from the inner macro rather than the outer one.What was the behavior or documentation before?
Using square brackets with
format!,print!, orprintln!produced:And the "no format string argument" diagnostic pointed at the opening bracket position rather than the full macro call.
What is the behavior or documentation after?
Using square brackets now produces a diagnostic that correctly names the invoked macro:
The "no format string argument" diagnostic now spans the entire macro invocation (e.g.,
format!()).Related issue or discussion (if any)
Resolves the TODO comments previously left in the test data referencing
orizi.Additional context
The bracket-forwarding logic (
left_bracket/right_bracketrewrite nodes) has been removed entirely. The generated code now unconditionally useswrite!(...)with parentheses, and unsupported bracket types are rejected before code generation viaunsupported_bracket_diagnostic.