mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: deprecate inline sum types
This commit is contained in:
parent
b154af032b
commit
ba1045e5fd
|
@ -10,8 +10,9 @@
|
||||||
- DOOM is now translated/compiled and launched on CI servers. A screenshot of the running game
|
- DOOM is now translated/compiled and launched on CI servers. A screenshot of the running game
|
||||||
is made via `vgret` and is compared to the expected result.
|
is made via `vgret` and is compared to the expected result.
|
||||||
- VLS performance improvements, especially on Windows.
|
- VLS performance improvements, especially on Windows.
|
||||||
- Add `v ls` tool for installing, for updating, and for launching VLS (V Language Server)
|
- `v ls` tool for installing, for updating, and for launching VLS (V Language Server).
|
||||||
- Support `assert condition, extra_message`, where the `extra_message` will be evaluated and shown if the assertion fails.
|
- Support `assert condition, extra_message`, where the `extra_message` will be evaluated and shown if the assertion fails.
|
||||||
|
- Anonymous sumtypes have been removed (deprecated for now) due to complicating the language and the compiler too much.
|
||||||
|
|
||||||
## V 0.3
|
## V 0.3
|
||||||
*30 Jun 2022*
|
*30 Jun 2022*
|
||||||
|
|
|
@ -124,7 +124,9 @@ struct VarConfig {
|
||||||
|
|
||||||
type Var = GlobalVar | LocalVar | ast.Ident
|
type Var = GlobalVar | LocalVar | ast.Ident
|
||||||
|
|
||||||
fn (mut g Gen) get_var_from_ident(ident ast.Ident) LocalVar|GlobalVar|Register {
|
type IdentVar = GlobalVar | LocalVar | Register
|
||||||
|
|
||||||
|
fn (mut g Gen) get_var_from_ident(ident ast.Ident) IdentVar {
|
||||||
mut obj := ident.obj
|
mut obj := ident.obj
|
||||||
if obj !in [ast.Var, ast.ConstField, ast.GlobalField, ast.AsmRegister] {
|
if obj !in [ast.Var, ast.ConstField, ast.GlobalField, ast.AsmRegister] {
|
||||||
obj = ident.scope.find(ident.name) or { g.n_error('unknown variable $ident.name') }
|
obj = ident.scope.find(ident.name) or { g.n_error('unknown variable $ident.name') }
|
||||||
|
|
|
@ -305,6 +305,8 @@ pub fn (mut p Parser) parse_language() ast.Language {
|
||||||
// parse_inline_sum_type parses the type and registers it in case the type is an anonymous sum type.
|
// parse_inline_sum_type parses the type and registers it in case the type is an anonymous sum type.
|
||||||
// It also takes care of inline sum types where parse_type only parses a standalone type.
|
// It also takes care of inline sum types where parse_type only parses a standalone type.
|
||||||
pub fn (mut p Parser) parse_inline_sum_type() ast.Type {
|
pub fn (mut p Parser) parse_inline_sum_type() ast.Type {
|
||||||
|
p.warn('inline sum types have been deprecated and will be removed on January 1, 2023 due ' +
|
||||||
|
'to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead')
|
||||||
variants := p.parse_sum_type_variants()
|
variants := p.parse_sum_type_variants()
|
||||||
if variants.len > 1 {
|
if variants.len > 1 {
|
||||||
if variants.len > parser.maximum_inline_sum_type_variants {
|
if variants.len > parser.maximum_inline_sum_type_variants {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/parser/tests/anon_sum_type_interface.vv:2:6: warning: inline sum types have been deprecated and will be removed on January 1, 2023 due to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead
|
||||||
|
1 | interface Foo {
|
||||||
|
2 | bar string | int
|
||||||
|
| ~~~~~~
|
||||||
|
3 | }
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/parser/tests/anon_sum_type_struct.vv:2:6: warning: inline sum types have been deprecated and will be removed on January 1, 2023 due to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead
|
||||||
|
1 | struct Foo {
|
||||||
|
2 | bar string | int
|
||||||
|
| ~~~~~~
|
||||||
|
3 | }
|
|
@ -1,3 +1,8 @@
|
||||||
|
vlib/v/parser/tests/inline_sum_type_optional_err.vv:1:11: warning: inline sum types have been deprecated and will be removed on January 1, 2023 due to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead
|
||||||
|
1 | fn foo() ?string | int {
|
||||||
|
| ~~~~~~
|
||||||
|
2 | return 0
|
||||||
|
3 | }
|
||||||
vlib/v/parser/tests/inline_sum_type_optional_err.vv:1:10: error: an inline sum type cannot be optional
|
vlib/v/parser/tests/inline_sum_type_optional_err.vv:1:10: error: an inline sum type cannot be optional
|
||||||
1 | fn foo() ?string | int {
|
1 | fn foo() ?string | int {
|
||||||
| ~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:4:6: warning: inline sum types have been deprecated and will be removed on January 1, 2023 due to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead
|
||||||
|
2 |
|
||||||
|
3 | struct Foo {
|
||||||
|
4 | bar int | string | token.Pos | bool | u32
|
||||||
|
| ~~~
|
||||||
|
5 | }
|
||||||
|
6 |
|
||||||
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:4:6: warning: an inline sum type expects a maximum of 3 types (5 were given)
|
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:4:6: warning: an inline sum type expects a maximum of 3 types (5 were given)
|
||||||
2 |
|
2 |
|
||||||
3 | struct Foo {
|
3 | struct Foo {
|
||||||
|
@ -5,6 +12,13 @@ vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:4:6: warnin
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
5 | }
|
5 | }
|
||||||
6 |
|
6 |
|
||||||
|
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:7:12: warning: inline sum types have been deprecated and will be removed on January 1, 2023 due to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead
|
||||||
|
5 | }
|
||||||
|
6 |
|
||||||
|
7 | fn foo(arg int | string | token.Pos | bool | u32) int | string | token.Pos | bool | u32 {
|
||||||
|
| ~~~
|
||||||
|
8 | return 1
|
||||||
|
9 | }
|
||||||
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:7:12: warning: an inline sum type expects a maximum of 3 types (5 were given)
|
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:7:12: warning: an inline sum type expects a maximum of 3 types (5 were given)
|
||||||
5 | }
|
5 | }
|
||||||
6 |
|
6 |
|
||||||
|
@ -12,6 +26,13 @@ vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:7:12: warni
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
8 | return 1
|
8 | return 1
|
||||||
9 | }
|
9 | }
|
||||||
|
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:7:51: warning: inline sum types have been deprecated and will be removed on January 1, 2023 due to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead
|
||||||
|
5 | }
|
||||||
|
6 |
|
||||||
|
7 | fn foo(arg int | string | token.Pos | bool | u32) int | string | token.Pos | bool | u32 {
|
||||||
|
| ~~~
|
||||||
|
8 | return 1
|
||||||
|
9 | }
|
||||||
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:7:51: warning: an inline sum type expects a maximum of 3 types (5 were given)
|
vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.vv:7:51: warning: an inline sum type expects a maximum of 3 types (5 were given)
|
||||||
5 | }
|
5 | }
|
||||||
6 |
|
6 |
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
vlib/v/parser/tests/option_sum_type_return_err.vv:1:22: warning: inline sum types have been deprecated and will be removed on January 1, 2023 due to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead
|
||||||
|
1 | fn option_sumtype() ?string | int {
|
||||||
|
| ~~~~~~
|
||||||
|
2 | return 0
|
||||||
|
3 | }
|
||||||
vlib/v/parser/tests/option_sum_type_return_err.vv:1:21: error: an inline sum type cannot be optional
|
vlib/v/parser/tests/option_sum_type_return_err.vv:1:21: error: an inline sum type cannot be optional
|
||||||
1 | fn option_sumtype() ?string | int {
|
1 | fn option_sumtype() ?string | int {
|
||||||
| ~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~
|
||||||
|
|
Loading…
Reference in New Issue
Block a user