From ba1045e5fd2476a653e8a18fc5b416dbe8d2aecb Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 30 Aug 2022 13:18:22 +0300 Subject: [PATCH] parser: deprecate inline sum types --- CHANGELOG.md | 3 ++- vlib/v/gen/native/gen.v | 4 ++- vlib/v/parser/parse_type.v | 2 ++ .../parser/tests/anon_sum_type_interface.out | 5 ++++ vlib/v/parser/tests/anon_sum_type_struct.out | 5 ++++ .../tests/inline_sum_type_optional_err.out | 5 ++++ ...sum_type_return_type_too_many_variants.out | 27 ++++++++++++++++--- .../tests/option_sum_type_return_err.out | 5 ++++ 8 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a05766ebc..65e4c3943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,9 @@ - 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. - 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. +- Anonymous sumtypes have been removed (deprecated for now) due to complicating the language and the compiler too much. ## V 0.3 *30 Jun 2022* diff --git a/vlib/v/gen/native/gen.v b/vlib/v/gen/native/gen.v index 63855f599..e20132ff5 100644 --- a/vlib/v/gen/native/gen.v +++ b/vlib/v/gen/native/gen.v @@ -124,7 +124,9 @@ struct VarConfig { 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 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') } diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 9beb3c101..07ea5de03 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -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. // 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 { + 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() if variants.len > 1 { if variants.len > parser.maximum_inline_sum_type_variants { diff --git a/vlib/v/parser/tests/anon_sum_type_interface.out b/vlib/v/parser/tests/anon_sum_type_interface.out index e69de29bb..60c5e3f6b 100644 --- a/vlib/v/parser/tests/anon_sum_type_interface.out +++ b/vlib/v/parser/tests/anon_sum_type_interface.out @@ -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 | } diff --git a/vlib/v/parser/tests/anon_sum_type_struct.out b/vlib/v/parser/tests/anon_sum_type_struct.out index e69de29bb..649513fb7 100644 --- a/vlib/v/parser/tests/anon_sum_type_struct.out +++ b/vlib/v/parser/tests/anon_sum_type_struct.out @@ -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 | } diff --git a/vlib/v/parser/tests/inline_sum_type_optional_err.out b/vlib/v/parser/tests/inline_sum_type_optional_err.out index b339f7233..85e7f5c34 100644 --- a/vlib/v/parser/tests/inline_sum_type_optional_err.out +++ b/vlib/v/parser/tests/inline_sum_type_optional_err.out @@ -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 1 | fn foo() ?string | int { | ~~~~~~~~~~~~~ diff --git a/vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.out b/vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.out index 027b103d2..3a03814d6 100644 --- a/vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.out +++ b/vlib/v/parser/tests/inline_sum_type_return_type_too_many_variants.out @@ -1,20 +1,41 @@ +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) - 2 | + 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: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) 5 | } - 6 | + 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: 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) 5 | } - 6 | + 6 | 7 | fn foo(arg int | string | token.Pos | bool | u32) int | string | token.Pos | bool | u32 { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | return 1 diff --git a/vlib/v/parser/tests/option_sum_type_return_err.out b/vlib/v/parser/tests/option_sum_type_return_err.out index 227a2ab21..fb8591062 100644 --- a/vlib/v/parser/tests/option_sum_type_return_err.out +++ b/vlib/v/parser/tests/option_sum_type_return_err.out @@ -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 1 | fn option_sumtype() ?string | int { | ~~~~~~~~~~~~~ -- 2.30.2