doc: fix match-expressions.adoc to cover all supported match targets#9759
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
orizi
left a comment
There was a problem hiding this comment.
@orizi made 2 comments.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on eytan-starkware and TomerStarkware).
docs/reference/src/components/cairo/modules/language_constructs/pages/match-expressions.adoc line 31 at r1 (raw file):
==== == Supported match targets
should probably mention recursive matching as well - but maybe not for this PR.
docs/reference/src/components/cairo/modules/language_constructs/pages/match-expressions.adoc line 53 at r1 (raw file):
Match expressions also work on `felt252`, integer types (`u8`, `u16`, `u32`, `u64`, `u128`, `i8`, `i16`, `i32`, `i64`, `i128`), `bool`, and short string literals (which are `felt252` values).
short string literals are simply other ways to write numeric value - of all types - not specifically felt252 but for that reason - should probably not be mentioned here at all.
98a53ca to
60c9b52
Compare
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on eytan-starkware).
docs/reference/src/components/cairo/modules/language_constructs/pages/match-expressions.adoc line 57 at r2 (raw file):
[source, cairo] ---- // Match on felt252
I don't think this is different from integers should just be numeric values,
If you still want to keep it, add a 1 case as it is now supported.
60c9b52 to
92ccca0
Compare
bea8cd2 to
54a1800
Compare
9da7ded to
09c04ab
Compare
09c04ab to
2710d6c
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware made 3 comments.
Reviewable status: 0 of 1 files reviewed, 3 unresolved discussions (waiting on orizi and TomerStarkware).
docs/reference/src/components/cairo/modules/language_constructs/pages/match-expressions.adoc line 31 at r1 (raw file):
Previously, orizi wrote…
should probably mention recursive matching as well - but maybe not for this PR.
Done.
docs/reference/src/components/cairo/modules/language_constructs/pages/match-expressions.adoc line 53 at r1 (raw file):
Previously, orizi wrote…
short string literals are simply other ways to write numeric value - of all types - not specifically
felt252but for that reason - should probably not be mentioned here at all.
Done.
docs/reference/src/components/cairo/modules/language_constructs/pages/match-expressions.adoc line 57 at r2 (raw file):
Previously, TomerStarkware wrote…
I don't think this is different from
integersshould just be numeric values,
If you still want to keep it, add a1case as it is now supported.
Done.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2710d6c7a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| === Match with fixed-size arrays | ||
|
|
||
| [source, cairo] |
There was a problem hiding this comment.
Remove fixed-size array match support claim
This section documents fixed-size array patterns in match, but the lowering path still rejects [T; N] as a matched type: create_node_for_patterns only handles numeric, enum, struct, and tuple types, and falls through to MatchDiagnostic::UnsupportedMatchedType for others (crates/cairo-lang-lowering/src/lower/flow_control/create_graph/patterns.rs, around match long_ty). As written, users following this example will hit an E3004 unsupported-type diagnostic instead of a working match.
Useful? React with 👍 / 👎.
orizi
left a comment
There was a problem hiding this comment.
@orizi resolved 2 discussions.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on eytan-starkware and TomerStarkware).

Summary
Expanded the match expressions documentation to include support for numeric types (
u8,u16,u32,u64,u128,i8,i16,i32,i64,i128),bool, and short string literals, in addition to the previously documentedenumandfelt252support. Added concrete code examples for integer and boolean matching patterns.Type of change
Please check one:
Why is this change needed?
The documentation was incomplete and potentially misleading by stating that only two kinds of match expressions were supported (enum and felt252), when in fact Cairo's match expressions work with a broader range of types including all integer types, booleans, and short string literals. This omission could cause developers to unnecessarily avoid using match expressions with these supported types.
What was the behavior or documentation before?
The documentation claimed that "Currently two kinds of match expression are supported" and only showed examples for enum and felt252 matching, with no mention of integer types, booleans, or short string literals.
What is the behavior or documentation after?
The documentation now accurately describes that match expressions support enums, felt252, all integer types (u8-u128, i8-i128), bool, and short string literals, with practical code examples demonstrating integer and boolean matching patterns.
Related issue or discussion (if any)
Additional context
This change helps developers understand the full capabilities of Cairo's match expressions, enabling them to write more idiomatic and readable code when working with numeric and boolean values.
Note
Low Risk
Low risk documentation-only change; the main risk is minor confusion if any listed supported targets diverge from actual compiler behavior.
Overview
Clarifies
match-expressions.adocby replacing the prior “two kinds supported” limitation with a broader Supported match targets section.Documents matching on numeric integer types and
boolwith concrete examples, and adds coverage/examples for struct/tuple destructuring, fixed-size array patterns, OR (|) patterns, and nested (recursive) patterns. Adds a small See also section linking to related pattern/expression docs.Written by Cursor Bugbot for commit 2710d6c. This will update automatically on new commits. Configure here.