-
Notifications
You must be signed in to change notification settings - Fork 327
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
Replace private
modifier node with field on supporting types
#11346
Conversation
… types. Also: - Rust parser tests: Switch to a builder-style API for defining expected `Function` ASTs to allow further changes to `Function` fields without rewriting all the tests again. - TreeToIr: Fix discarded module-level `diag`; add a test that covers module diagnostics. - Syntax: Disallow `private` methods in function blocks.
3c6a075
to
bfd074f
Compare
private | ||
private | ||
"""); | ||
assertSingleSyntaxError( |
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.
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.
There's no risk of rejecting this due to the one-private-declaration-per-module rule--the second private
is not a declaration but a field of the Function
.
Some(statement) => Tree::app( | ||
private.with_error(match visibility_context { | ||
VisibilityContext::Public => SyntaxError::StmtUnexpectedPrivateSubject, | ||
VisibilityContext::Private => SyntaxError::StmtUnexpectedPrivateContext, | ||
}), | ||
statement, | ||
), |
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.
It took me a good while to understand, why do we always set error here. I assumed that the responsibility of this function is to make statement a private object, not that it is already applied and any excessive private is an error. Please rename/add short docs for this function.
fn into_private_keyword(item: Item) -> token::PrivateKeyword { | ||
let Item::Token(keyword) = item else { unreachable!() }; | ||
let token::Variant::PrivateKeyword(variant) = keyword.variant else { unreachable!() }; | ||
keyword.with_variant(variant) |
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.
The same function is in statement.rs
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.
Implemented some downcasting helpers so we don't need a special function for this case.
for token in keywords { | ||
let Item::Token(keyword) = token else { unreachable!() }; | ||
let token::Variant::PrivateKeyword(variant) = keyword.variant else { unreachable!() }; | ||
let keyword = keyword.with_variant(variant); |
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.
Another into_private_keyword
logic
lib/rust/parser/src/syntax/tree.rs
Outdated
/// A `private` declaration. | ||
Private { | ||
pub keyword: token::Private<'s>, | ||
pub body: Option<Tree<'s>>, | ||
pub keyword: token::PrivateKeyword<'s>, |
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.
This is for making a module private, right? I would then add this info here.
Pull Request Description
Eliminate
private
modifier-node:private
is a field in supporting types, or a single-token node in the case ofprivate
declarations.Important Notes
Function
ASTs to allow further changes toFunction
fields without rewriting all the tests again.diag
; add a test that covers module diagnostics.private
methods in function blocks. (Previously this was enforced in the compiler.)Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
or the Snowflake database integration, a run of the Extra Tests has been scheduled.