forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disables usage of parenthesis in unit enum variants. (FuelLabs#3743)
With these changes it is no longer possible to do `Option::None()` instead it should be done with `Option::None`. This changes also fixes enum turbofish without parenthesis so `Option::None::<T>` can be used. Ref FuelLabs#3585 (Does not close but addresses other issue mentioned on the comments) Closes FuelLabs#3375 Co-authored-by: Joshua Batty <[email protected]>
- Loading branch information
1 parent
1c4f3e2
commit a97c97f
Showing
26 changed files
with
174 additions
and
32 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
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
13 changes: 13 additions & 0 deletions
13
test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/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,13 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-2C926E0DE5E7A78F' | ||
|
||
[[package]] | ||
name = 'enum_variant_unit' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-2C926E0DE5E7A78F' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/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,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "enum_variant_unit" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
1 change: 1 addition & 0 deletions
1
test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/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 @@ | ||
[] |
18 changes: 18 additions & 0 deletions
18
test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/inner_lib.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,18 @@ | ||
library inner_lib; | ||
|
||
pub enum MyEnum { | ||
VariantA: (), | ||
VariantB: u64 | ||
} | ||
|
||
pub fn func() -> bool { | ||
true | ||
} | ||
|
||
pub struct S2 {} | ||
|
||
impl S2 { | ||
pub fn new2() -> Self { | ||
S2 {} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/src/lib_a.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,5 @@ | ||
library lib_a; | ||
|
||
dep inner_lib; | ||
|
||
use inner_lib::*; |
46 changes: 46 additions & 0 deletions
46
test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/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,46 @@ | ||
script; | ||
|
||
dep lib_a; | ||
|
||
fn func() -> bool { | ||
true | ||
} | ||
|
||
struct S {} | ||
|
||
impl S { | ||
fn new2() -> Self { | ||
S {} | ||
} | ||
} | ||
|
||
fn main() -> u64 { | ||
|
||
// check that calling function and methods with no parameters still requires parenthesis | ||
let b = func; | ||
let b = func(); | ||
|
||
|
||
let s = S::new; | ||
let s = S::new(); | ||
|
||
|
||
let b = lib_a::inner_lib::func; | ||
let b = lib_a::inner_lib::func(); | ||
|
||
|
||
let s = lib_a::inner_lib::S2::new2; | ||
let s = lib_a::inner_lib::S2::new2(); | ||
|
||
|
||
let n: Option<u64> = Option::None(); | ||
|
||
|
||
let n = Option::None::<u64>(); | ||
|
||
|
||
let n = lib_a::inner_lib::MyEnum::VariantA; | ||
let n = lib_a::inner_lib::MyEnum::VariantA(); | ||
|
||
5 | ||
} |
22 changes: 22 additions & 0 deletions
22
test/src/e2e_vm_tests/test_programs/should_fail/enum_variant_unit/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,22 @@ | ||
category = "fail" | ||
|
||
# check: $()let b = func; | ||
# nextln: $()Identifier "func" was used as a variable, but it is actually a function. | ||
|
||
# check: $()let s = S::new; | ||
# nextln: $()Could not find symbol "new" in this scope. | ||
|
||
# check: $()let b = lib_a::inner_lib::func; | ||
# nextln: $()The function "func" was called without parentheses. Try adding (). | ||
|
||
# check: $()let s = lib_a::inner_lib::S2::new2; | ||
# nextln: $()Could not find symbol "new2" in this scope. | ||
|
||
# check: $()let n: Option<u64> = Option::None(); | ||
# nextln: $()The enum variant `None` is of type `unit`, so its constructor does not take arguments or parentheses. Try removing the (). | ||
|
||
# check: $()let n = Option::None::<u64>(); | ||
# nextln: $()The enum variant `None` is of type `unit`, so its constructor does not take arguments or parentheses. Try removing the (). | ||
|
||
# check: $()let n = lib_a::inner_lib::MyEnum::VariantA(); | ||
# nextln: $()The enum variant `VariantA` is of type `unit`, so its constructor does not take arguments or parentheses. Try removing the (). |
2 changes: 1 addition & 1 deletion
2
test/src/e2e_vm_tests/test_programs/should_fail/insufficient_type_info_enum/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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
script; | ||
|
||
fn main() -> bool { | ||
let o = Option::None(); | ||
let o = Option::None; | ||
true | ||
} |
2 changes: 1 addition & 1 deletion
2
test/src/e2e_vm_tests/test_programs/should_fail/insufficient_type_info_enum/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
category = "fail" | ||
|
||
# check: Option::None() | ||
# check: Option::None | ||
# nextln: $()Cannot infer type for type parameter "T". Insufficient type information provided. Try annotating its type. |
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
Oops, something went wrong.