Skip to content
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(core): add state mutability computation from world param #2049

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: apply review comments
  • Loading branch information
glihm committed Jun 13, 2024
commit ff3e154475abcce298aed1c7cb2c2b158e2c8550
7 changes: 1 addition & 6 deletions crates/dojo-lang/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,7 @@ impl DojoContract {
param_list: ast::ParamList,
fn_diagnostic_item: ids::SyntaxStablePtrId,
) -> (String, bool) {
self_param::check_self_parameter(
db,
&param_list,
fn_diagnostic_item,
&mut self.diagnostics,
);
self_param::check_parameter(db, &param_list, fn_diagnostic_item, &mut self.diagnostics);

let world_injection = world_param::parse_world_injection(
db,
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo-lang/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl DojoInterface {
.map(|e| e.as_syntax_node().get_text(db))
.collect::<Vec<_>>();

self_param::check_self_parameter(db, &param_list, diagnostic_item, &mut self.diagnostics);
self_param::check_parameter(db, &param_list, diagnostic_item, &mut self.diagnostics);

let world_injection = world_param::parse_world_injection(
db,
Expand Down
5 changes: 3 additions & 2 deletions crates/dojo-lang/src/syntax/self_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ use crate::syntax::utils as syntax_utils;

const SELF_PARAM_NAME: &str = "self";

/// Checks if the given function is not using `self` param.
/// Checks if the given function parameter is using `self` instead of `world` param.
/// Adds diagnostic if that case.
///
/// # Arguments
///
/// - `db` - The syntax group.
/// - `param_list` - The parameter list of the function.
/// - `fn_diagnostic_item` - The diagnostic item of the function.
/// - `diagnostics` - The diagnostics vector.
pub fn check_self_parameter(
pub fn check_parameter(
db: &dyn SyntaxGroup,
param_list: &ast::ParamList,
fn_diagnostic_item: ids::SyntaxStablePtrId,
Expand Down
10 changes: 5 additions & 5 deletions crates/dojo-lang/src/syntax/world_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/// Checks if the given parameter is the `world` parameter.
///
/// The `world` must be named `world`, and be placed first in the argument list, without type.
/// The `world` must be named `world`, and be placed first in the argument list.
pub fn is_world_param(param_name: &str, param_type: &str) -> bool {
param_name == WORLD_PARAM_NAME
&& (param_type == WORLD_PARAM_TYPE || param_type == WORLD_PARAM_TYPE_SNAPSHOT)
Expand All @@ -27,11 +27,11 @@
/// Extracts the state mutability of a function from the `world` parameter.
///
/// Checks if the function has only one `world` parameter (or None).
/// The `world` must be named `world`, and be placed first in the argument list, without type.
/// The `world` must be named `world`, and be placed first in the argument list.
///
/// `fn ext(ref world)` -> external.
/// `fn view(world)` -> view.
/// `fn noworld()` -> view.
/// `fn func1(ref world)` // would be external.
/// `fn func2(world)` // would be view.
/// `fn func3()` // would be view.
///
/// Returns
/// * The [`WorldParamInjectionKind`] determined from the function's params list.
Expand All @@ -54,13 +54,13 @@
}

if has_world_injected {
diagnostics.push(PluginDiagnostic {
stable_ptr: fn_diagnostic_item,
message: "Only one world parameter is allowed".to_string(),
severity: Severity::Error,
});

return;

Check warning on line 63 in crates/dojo-lang/src/syntax/world_param.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo-lang/src/syntax/world_param.rs#L57-L63

Added lines #L57 - L63 were not covered by tests
} else {
has_world_injected = true;
}
Expand Down
Loading