Skip to content

Commit

Permalink
fix: ensure free function are not impacted by the injection of world …
Browse files Browse the repository at this point in the history
…and self (#1733)

* fix: ensure free function are not impacted by the injection of world and self

* fix: rewrite functions only in impl that target ContractState
  • Loading branch information
glihm authored Mar 31, 2024
1 parent 45e8d64 commit c4b15c0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 249 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ output.txt
crates/benches/bench_results.txt
**/generated
.vscode
bindings
9 changes: 6 additions & 3 deletions crates/dojo-lang/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ impl DojoContract {
has_storage = true;
return system.merge_storage(db, struct_ast.clone());
}
} else if let ast::ModuleItem::FreeFunction(fn_ast) = el {
return system.rewrite_function(db, fn_ast.clone());
} else if let ast::ModuleItem::Impl(impl_ast) = el {
return system.rewrite_impl(db, impl_ast.clone());
// If an implementation is not targetting the ContractState,
// the auto injection of self and world is not applied.
let trait_path = impl_ast.trait_path(db).node.get_text(db);
if trait_path.contains("<ContractState>") {
return system.rewrite_impl(db, impl_ast.clone());
}
}

vec![RewriteNode::Copied(el.as_syntax_node())]
Expand Down
Loading

0 comments on commit c4b15c0

Please sign in to comment.