-
Notifications
You must be signed in to change notification settings - Fork 601
Check on enum variant type matching in patterns #7725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 4 files at r1, all commit messages.
Reviewable status: 1 of 4 files reviewed, 3 unresolved discussions (waiting on @orizi)
crates/cairo-lang-semantic/src/expr/test_data/match
line 260 at r1 (raw file):
//! > ========================================================================== //! > Test match on variant without args.
add a test where we use A::One
and match on the pattern One
crates/cairo-lang-semantic/src/expr/compute.rs
line 2630 at r1 (raw file):
let (concrete_enum, n_snapshots) = extract_concrete_enum_from_pattern_and_validate(ctx, pattern, ty, generic_variant.enum_id)?; let db = ctx.db;
The local db variable is unnecessary
crates/cairo-lang-semantic/src/expr/compute.rs
line 2638 at r1 (raw file):
.map_err(|_| ctx.diagnostics.report(pattern.stable_ptr(db), UnknownEnum))?; let needs_args = concrete_variant.ty != unit_ty(db);
using concre_variant.ty means we Option<()>::Some does not need args,
is this intended? add tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status: 1 of 4 files reviewed, 3 unresolved discussions (waiting on @eytan-starkware and @TomerStarkware)
crates/cairo-lang-semantic/src/expr/compute.rs
line 2630 at r1 (raw file):
Previously, TomerStarkware wrote…
The local db variable is unnecessary
it is fine IMO - as it is used a lot of times.
d0b74a4
to
b463e1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 of 4 files reviewed, 3 unresolved discussions (waiting on @orizi and @TomerStarkware)
crates/cairo-lang-semantic/src/expr/compute.rs
line 2630 at r1 (raw file):
Previously, orizi wrote…
it is fine IMO - as it is used a lot of times.
Actually added another use now
crates/cairo-lang-semantic/src/expr/compute.rs
line 2638 at r1 (raw file):
Previously, TomerStarkware wrote…
using concre_variant.ty means we Option<()>::Some does not need args,
is this intended? add tests
Changed it to use generic_variant to have consistent error reporting as discussed
crates/cairo-lang-semantic/src/expr/test_data/match
line 260 at r1 (raw file):
Previously, TomerStarkware wrote…
add a test where we
use A::One
and match on the patternOne
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 3 files at r2.
Reviewable status: 3 of 4 files reviewed, 4 unresolved discussions (waiting on @TomerStarkware)
crates/cairo-lang-semantic/src/diagnostic.rs
line 1014 at r2 (raw file):
"Type constraints syntax is not enabled in the current crate.".into() } SemanticDiagnosticKind::PatternMissingArgs(variant_id) => {
add that this is a warning instead of an error - to not fully break existing libs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 3 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @eytan-starkware)
b463e1d
to
21833a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware)
crates/cairo-lang-semantic/src/diagnostic.rs
line 1014 at r2 (raw file):
Previously, orizi wrote…
add that this is a warning instead of an error - to not fully break existing libs.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status: 0 of 6 files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
crates/cairo-lang-lowering/src/test_data/match
line 1741 at r3 (raw file):
//! > semantic_diagnostics warning: Pattern missing subpattern for the parameter of variant `core::option::Option::Some`. Consider using `core::option::Option::Some(_)`
extract Some
from the usage to shorten and make clearer.
Suggestion:
warning: Pattern missing subpattern for the payload of variant. Consider using `Some(_)`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 6 files at r3.
Reviewable status: 1 of 6 files reviewed, 1 unresolved discussion (waiting on @eytan-starkware and @TomerStarkware)
21c7c1c
to
d6de8e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 6 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware)
crates/cairo-lang-lowering/src/test_data/match
line 1741 at r3 (raw file):
Previously, orizi wrote…
extract
Some
from the usage to shorten and make clearer.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 6 files at r4, all commit messages.
Reviewable status: 5 of 6 files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
crates/cairo-lang-semantic/src/expr/compute.rs
line 2632 at r4 (raw file):
let db = ctx.db; // TODO(lior): Should we report a diagnostic here?
?
Code quote:
// TODO(lior): Should we report a diagnostic here?
crates/cairo-lang-semantic/src/expr/compute.rs
line 2647 at r4 (raw file):
ast::Pattern::Enum(pattern) => pattern.path(db), ast::Pattern::Path(p) => p.clone(), _ => unreachable!(),
Suggestion:
_ => unreachable!("string explaining why"),
180886e
to
a28fb9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 5 of 6 files reviewed, 2 unresolved discussions (waiting on @orizi and @TomerStarkware)
crates/cairo-lang-semantic/src/expr/compute.rs
line 2632 at r4 (raw file):
Previously, orizi wrote…
?
Done.
crates/cairo-lang-semantic/src/expr/compute.rs
line 2647 at r4 (raw file):
ast::Pattern::Enum(pattern) => pattern.path(db), ast::Pattern::Path(p) => p.clone(), _ => unreachable!(),
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @eytan-starkware)
When building a semantic model a check is expected that pattern is legal. When we match an option, we expect a case `Some` to be illegal, as it ignores the parameter. The expected pattern would be `Some(_)`. This PR adds that check and raises a warning when needed. commit-id:8eb351cd
a28fb9c
to
7f21d34
Compare
When building a semantic model a check is expected that pattern is legal.
When we match an option, we expect a case
Some
to be illegal, as it ignores the parameter. The expected pattern would beSome(_)
.This PR adds that check.