-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue where compiler doesn't reject method call on storage struct
(cherry picked from commit 2a1cd2aa974570ec86314700ec09feba26d0f6b6)
- Loading branch information
Showing
4 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
crates/analyzer/tests/snapshots/errors__call_method_in_storage.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
source: crates/analyzer/tests/errors.rs | ||
assertion_line: 323 | ||
expression: "error_string(&path, test_files::fixture(path))" | ||
--- | ||
error: struct functions can only be called on struct in memory | ||
┌─ compile_errors/call_method_in_storage.fe:16:9 | ||
│ | ||
16 │ self.bar.get_x() | ||
│ ^^^^^^^^ ----- hint: copy the struct to memory with `.to_mem()` | ||
│ │ | ||
│ this value is in storage | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
crates/test-files/fixtures/compile_errors/call_method_in_storage.fe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
struct Bar { | ||
pub x: u256 | ||
|
||
pub fn get_x(self) -> u256{ | ||
return self.x | ||
} | ||
} | ||
|
||
contract Foo { | ||
bar: Bar | ||
|
||
pub fn __init__(mut self) { | ||
self.bar = Bar( x: 2 ) | ||
} | ||
fn yay(self) { | ||
self.bar.get_x() | ||
} | ||
} |