-
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.
checker, cgen: fix the static from_string method of Enum across mods(fix
- Loading branch information
Showing
8 changed files
with
162 additions
and
22 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
47 changes: 47 additions & 0 deletions
47
vlib/v/checker/tests/modules/enum_from_string_in_different_mods.out
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,47 @@ | ||
main.v:3:15: error: module `amod` type `MyEnum` is private | ||
1 | module main | ||
2 | | ||
3 | import amod { MyEnum } | ||
| ~~~~~~ | ||
4 | | ||
5 | fn main() { | ||
main.v:6:6: error: module `amod` type `amod.MyEnum` is private | ||
4 | | ||
5 | fn main() { | ||
6 | _ = MyEnum.from_string('item1') | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
7 | _ = amod.MyEnum.from_string('item1') | ||
8 | _ = amod.MyStruct.from_string('item1') | ||
main.v:6:4: error: assignment mismatch: 1 variable(s) but `MyEnum.from_string()` returns 0 value(s) | ||
4 | | ||
5 | fn main() { | ||
6 | _ = MyEnum.from_string('item1') | ||
| ^ | ||
7 | _ = amod.MyEnum.from_string('item1') | ||
8 | _ = amod.MyStruct.from_string('item1') | ||
main.v:7:11: error: module `amod` type `amod.MyEnum` is private | ||
5 | fn main() { | ||
6 | _ = MyEnum.from_string('item1') | ||
7 | _ = amod.MyEnum.from_string('item1') | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
8 | _ = amod.MyStruct.from_string('item1') | ||
9 | } | ||
main.v:7:4: error: assignment mismatch: 1 variable(s) but `amod.MyEnum.from_string()` returns 0 value(s) | ||
5 | fn main() { | ||
6 | _ = MyEnum.from_string('item1') | ||
7 | _ = amod.MyEnum.from_string('item1') | ||
| ^ | ||
8 | _ = amod.MyStruct.from_string('item1') | ||
9 | } | ||
main.v:8:11: error: expected enum, but `amod.MyStruct` is struct | ||
6 | _ = MyEnum.from_string('item1') | ||
7 | _ = amod.MyEnum.from_string('item1') | ||
8 | _ = amod.MyStruct.from_string('item1') | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
9 | } | ||
main.v:8:4: error: assignment mismatch: 1 variable(s) but `amod.MyStruct.from_string()` returns 0 value(s) | ||
6 | _ = MyEnum.from_string('item1') | ||
7 | _ = amod.MyEnum.from_string('item1') | ||
8 | _ = amod.MyStruct.from_string('item1') | ||
| ^ | ||
9 | } |
8 changes: 8 additions & 0 deletions
8
vlib/v/checker/tests/modules/enum_from_string_in_different_mods/amod/amod.v
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 @@ | ||
module amod | ||
|
||
enum MyEnum { | ||
item1 | ||
item2 | ||
} | ||
|
||
pub struct MyStruct {} |
9 changes: 9 additions & 0 deletions
9
vlib/v/checker/tests/modules/enum_from_string_in_different_mods/main.v
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,9 @@ | ||
module main | ||
|
||
import amod { MyEnum } | ||
|
||
fn main() { | ||
_ = MyEnum.from_string('item1') | ||
_ = amod.MyEnum.from_string('item1') | ||
_ = amod.MyStruct.from_string('item1') | ||
} |
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
6 changes: 6 additions & 0 deletions
6
vlib/v/tests/modules/enum_from_string_in_different_mods/amod/amod.v
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 @@ | ||
module amod | ||
|
||
pub enum MyEnum { | ||
item1 | ||
item2 | ||
} |
10 changes: 10 additions & 0 deletions
10
vlib/v/tests/modules/enum_from_string_in_different_mods/main_test.v
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,10 @@ | ||
module main | ||
|
||
import amod { MyEnum } | ||
|
||
fn test_main() { | ||
item1 := MyEnum.from_string('item1')? | ||
assert item1 == MyEnum.item1 | ||
item2 := amod.MyEnum.from_string('item2')? | ||
assert item2 == MyEnum.item2 | ||
} |