-
Notifications
You must be signed in to change notification settings - Fork 599
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
feat: add self keyword to import a module #7366
base: main
Are you sure you want to change the base?
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.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions
a discussion (no related file):
add tests in:
crates/cairo-lang-semantic/src/expr/semantic_test_data/use
should cover both diagnostics for cases it makes no sense, as well usages in cases it does.
crates/cairo-lang-semantic/src/resolve/mod.rs
line 807 at r1 (raw file):
return Ok(ResolvedConcreteItem::Module(*module_id)); } }
handle enum
as well.
makes sure this is not happening in other cases. (such as a trait or an impl).
Suggestion:
// Handle the 'self' keyword in import paths - resolves to the containing module
if ident == SELF_KW {
// match instead of if let here.
if let ResolvedConcreteItem::Module(module_id) = containing_item {
return Ok(ResolvedConcreteItem::Module(*module_id));
}
}
hey @orizi, when running the tests, I'm getting failures because the tests are expecting the original behavior (where self is not recognized as a keyword). I believe I need to run with CAIRO_FIX_TESTS=1 to update the test expectations, did that and i'm still getting the same error message failures:
---- expr::test::expr_semantics::use_ stdout ----
thread 'expr::test::expr_semantics::use_' panicked at crates/cairo-lang-test-utils/src/parse_test_file.rs:467:5:
Test "Test self keyword in module imports" failed.
In /Users/g4titan/cairo/crates/cairo-lang-semantic/src/expr/semantic_test_data/use:1521.
`expect_diagnostics` is false, but diagnostics were generated:
Test "Test self keyword with nested modules" failed.
In /Users/g4titan/cairo/crates/cairo-lang-semantic/src/expr/semantic_test_data/use:1579.
`expect_diagnostics` is false, but diagnostics were generated:
Test "Test enum with self keyword" failed.
In /Users/g4titan/cairo/crates/cairo-lang-semantic/src/expr/semantic_test_data/use:1643.
`expect_diagnostics` is false, but diagnostics were generated:
Summary: 30 passed, 3 failed:
test_expr_semantics::use::"Test self keyword in module imports" (line: 1521)
test_expr_semantics::use::"Test self keyword with nested modules" (line: 1579)
test_expr_semantics::use::"Test enum with self keyword" (line: 1643)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
expr::test::expr_semantics::use_
test result: FAILED. 97 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 4.69s
error: test failed, to rerun pass `-p cairo-lang-semantic --lib` |
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 3 files reviewed, 3 unresolved discussions (waiting on @g4titanx)
crates/cairo-lang-semantic/src/expr/semantic_test_data/use
line 1524 at r2 (raw file):
//! > test_runner_name test_expr_semantics(expect_diagnostics: false)
when expecting diagnostics - do this.
Suggestion:
test_expr_semantics(expect_diagnostics: true)
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 3 files reviewed, 5 unresolved discussions (waiting on @g4titanx)
crates/cairo-lang-semantic/src/expr/semantic_test_data/use
line 1538 at r2 (raw file):
X::Y; Y }
simplify the others similarly.
Suggestion:
//! > module_code
mod x {
mod y {
pub const Z: u8 = 2;
}
}
use x::y::self;
//! > function_body
//! > expr_code
y::Z
crates/cairo-lang-semantic/src/expr/semantic_test_data/use
line 1569 at r2 (raw file):
error[E0006]: Identifier not found. --> lib.cairo:6:14 use X::{ self, Y };
this means the actual solution is not correct - i believe you are attempting to resolve during the first step, instead of the last.
Code quote:
use X::{ self, Y };
okay done @orizi |
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.
please reply to everything in https://reviewable.io/reviews/starkware-libs/cairo/7366#-
to keep threads.
Reviewed 1 of 3 files at r2, all commit messages.
Reviewable status: 1 of 3 files reviewed, 5 unresolved discussions (waiting on @g4titanx)
crates/cairo-lang-semantic/src/expr/semantic_test_data/use
line 1569 at r2 (raw file):
Previously, orizi wrote…
this means the actual solution is not correct - i believe you are attempting to resolve during the first step, instead of the last.
there shouldn't be diagnostics here.
this PR fixes #7279