Skip to content

doc: fix match-expressions.adoc to cover all supported match targets#9759

Open
eytan-starkware wants to merge 1 commit intomainfrom
eytan_graphite/doc_fix_match-expressions.adoc_to_cover_all_supported_match_targets
Open

doc: fix match-expressions.adoc to cover all supported match targets#9759
eytan-starkware wants to merge 1 commit intomainfrom
eytan_graphite/doc_fix_match-expressions.adoc_to_cover_all_supported_match_targets

Conversation

@eytan-starkware
Copy link
Copy Markdown
Contributor

@eytan-starkware eytan-starkware commented Mar 19, 2026

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 documented enum and felt252 support. Added concrete code examples for integer and boolean matching patterns.


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?

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.adoc by replacing the prior “two kinds supported” limitation with a broader Supported match targets section.

Documents matching on numeric integer types and bool with 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.

Copy link
Copy Markdown
Contributor Author

eytan-starkware commented Mar 19, 2026

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

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@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.

@eytan-starkware eytan-starkware changed the base branch from eytan_graphite/doc_delete_obsolete_cairo_0_feature_parity_roadmap to main March 22, 2026 08:50
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/doc_fix_match-expressions.adoc_to_cover_all_supported_match_targets branch from 98a53ca to 60c9b52 Compare March 22, 2026 08:51
Copy link
Copy Markdown
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

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

@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.

@eytan-starkware eytan-starkware changed the base branch from main to graphite-base/9759 March 22, 2026 09:08
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/doc_fix_match-expressions.adoc_to_cover_all_supported_match_targets branch from 60c9b52 to 92ccca0 Compare March 22, 2026 09:09
@eytan-starkware eytan-starkware changed the base branch from graphite-base/9759 to main March 22, 2026 09:09
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/doc_fix_match-expressions.adoc_to_cover_all_supported_match_targets branch 2 times, most recently from 9da7ded to 09c04ab Compare March 22, 2026 09:59
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/doc_fix_match-expressions.adoc_to_cover_all_supported_match_targets branch from 09c04ab to 2710d6c Compare March 22, 2026 11:05
Copy link
Copy Markdown
Contributor Author

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@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 felt252 but 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 integers should just be numeric values,
If you still want to keep it, add a 1 case as it is now supported.

Done.

@eytan-starkware eytan-starkware marked this pull request as ready for review March 22, 2026 11:05
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +94 to +96
=== Match with fixed-size arrays

[source, cairo]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@orizi resolved 2 discussions.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on eytan-starkware and TomerStarkware).

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.

4 participants