Sitelet https://github.com/starkware-libs/cairo/pull/10222
Skip to content

fix(semantic): attribute format!/print! bracket errors to the right macro - #10222

Merged
orizi merged 1 commit into
mainfrom
orizi/07-20-fix_semantic_attribute_format__print_bracket_errors_to_the_right_macro
Jul 21, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/07-20-fix_semantic_attribute_format__print_bracket_errors_to_the_right_macro

Conversation

@orizi

@orizi orizi commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The format!, print!, and println! macros now require parentheses as their bracket type. Previously, these macros forwarded whatever bracket type was used (e.g., format![...]) directly into the generated write!/writeln! call, which caused the "unsupported bracket type" diagnostic to incorrectly reference write or writeln instead 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 inner write!/writeln! call.

Additionally, the "no params" diagnostic span for format!() and print!() was corrected to point at the entire macro invocation rather than just the opening bracket.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

When a user wrote format![...] or print![...], the diagnostic reported that macro write does not support this bracket type, which was confusing because the user never invoked write directly. The root cause was that the bracket tokens were forwarded verbatim into the generated write! 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!, or println! produced:

error[E2200]: Plugin diagnostic: Macro `write` does not support this bracket type.

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:

error[E2200]: Plugin diagnostic: Macro `format` does not support this bracket type.

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_bracket rewrite nodes) has been removed entirely. The generated code now unconditionally uses write!(...) with parentheses, and unsupported bracket types are rejected before code generation via unsupported_bracket_diagnostic.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi marked this pull request as ready for review July 20, 2026 10:25
@cursor

cursor Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Compiler inline-macro plugin and diagnostic text/span changes only; behavior is tightened for invalid brackets and covered by existing semantic test data.

Overview
format!, print!, and println! now reject non-parenthesis argument lists before expansion and always emit inner write! / writeln! with (...), instead of copying the user’s bracket tokens into the generated code.

A shared extract_parenthesized_macro helper in plugin_utils centralizes legacy-macro parsing and unsupported-bracket diagnostics so errors name the macro the user wrote (e.g. format) rather than the inner write / writeln expansion. unsupported_bracket_diagnostic was split so the inner path can return a plain PluginDiagnostic for reuse.

Diagnostic snapshots were updated: wrong-bracket messages use the outer macro name, and the missing format-string case for empty format!() / print!() spans the full invocation.

Reviewed by Cursor Bugbot for commit f46890d. Bugbot is set up for automated code reviews on this repo. Configure here.

@eytan-starkware eytan-starkware left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

@orizi
orizi force-pushed the orizi/07-20-fix_semantic_attribute_format__print_bracket_errors_to_the_right_macro branch from 2ecc736 to d511f21 Compare July 20, 2026 15:27

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.
@orizi
orizi force-pushed the orizi/07-20-fix_semantic_attribute_format__print_bracket_errors_to_the_right_macro branch from d511f21 to f46890d Compare July 20, 2026 15:32

@eytan-starkware eytan-starkware left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@eytan-starkware reviewed 4 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@orizi
orizi added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit 7047765 Jul 21, 2026
55 checks passed
@orizi
orizi deleted the orizi/07-20-fix_semantic_attribute_format__print_bracket_errors_to_the_right_macro branch July 21, 2026 14:22
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.

3 participants