-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for calling of associated functions as method calls.
This adds a new error and checking for calls of associated functions using method call syntax. This means for code like the following: ``` struct Bar {} impl Bar { fn associated() {} } fn main() -> u64 { let bar = Bar {}; bar.associated(); 0 } ``` we now emit an error: ``` error --> main.sw:11:3 | 9 | 10 | let bar = Bar {}; 11 | bar.associated(); | ^^^^^^^^^^^^^^^^ Cannot call associated function "associated" as method call. Use associated function syntax instead. 12 | 0 13 | } | ``` This brings us closer to Rust behaviour, which also checks for this and only allows functions taking a self to be called with method call syntax. It adds a few more tests for this and also updates some standard library trait methods to take self so they work with the new check.
- Loading branch information
Showing
18 changed files
with
111 additions
and
21 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
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
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
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
4 changes: 4 additions & 0 deletions
4
test/src/e2e_vm_tests/test_programs/should_fail/associated_fn_as_method_call/Forc.lock
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,4 @@ | ||
[[package]] | ||
name = 'associated_fn_as_method_call' | ||
source = 'root' | ||
dependencies = [] |
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_fail/associated_fn_as_method_call/Forc.toml
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,6 @@ | ||
[project] | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
license = "Apache-2.0" | ||
name = "associated_fn_as_method_call" | ||
entry = "main.sw" | ||
implicit-std = false |
1 change: 1 addition & 0 deletions
1
.../e2e_vm_tests/test_programs/should_fail/associated_fn_as_method_call/json_abi_oracle.json
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 @@ | ||
[] |
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_fail/associated_fn_as_method_call/src/main.sw
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,13 @@ | ||
script; | ||
|
||
struct Bar {} | ||
|
||
impl Bar { | ||
fn associated() {} | ||
} | ||
|
||
fn main() -> u64 { | ||
let bar = Bar {}; | ||
bar.associated(); | ||
0 | ||
} |
4 changes: 4 additions & 0 deletions
4
test/src/e2e_vm_tests/test_programs/should_fail/associated_fn_as_method_call/test.toml
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,4 @@ | ||
category = "fail" | ||
|
||
# check: bar.associated() | ||
# nextln: $()Cannot call associated function "associated" as a method. Use associated function syntax instead. |
4 changes: 4 additions & 0 deletions
4
.../src/e2e_vm_tests/test_programs/should_fail/associated_fn_params_as_method_call/Forc.lock
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,4 @@ | ||
[[package]] | ||
name = 'associated_fn_params_as_method_call' | ||
source = 'root' | ||
dependencies = [] |
6 changes: 6 additions & 0 deletions
6
.../src/e2e_vm_tests/test_programs/should_fail/associated_fn_params_as_method_call/Forc.toml
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,6 @@ | ||
[project] | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
license = "Apache-2.0" | ||
name = "associated_fn_params_as_method_call" | ||
entry = "main.sw" | ||
implicit-std = false |
1 change: 1 addition & 0 deletions
1
..._tests/test_programs/should_fail/associated_fn_params_as_method_call/json_abi_oracle.json
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 @@ | ||
[] |
13 changes: 13 additions & 0 deletions
13
...rc/e2e_vm_tests/test_programs/should_fail/associated_fn_params_as_method_call/src/main.sw
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,13 @@ | ||
script; | ||
|
||
struct Bar {} | ||
|
||
impl Bar { | ||
fn associated() {} | ||
} | ||
|
||
fn main() -> u64 { | ||
let bar = Bar {}; | ||
bar.associated(); | ||
0 | ||
} |
4 changes: 4 additions & 0 deletions
4
.../src/e2e_vm_tests/test_programs/should_fail/associated_fn_params_as_method_call/test.toml
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,4 @@ | ||
category = "fail" | ||
|
||
# check: bar.associated() | ||
# nextln: $()Cannot call associated function "associated" as a method. Use associated function syntax instead. |