From 8db1aaafd518396452ccde6e49a42317b30fcd67 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Tue, 8 Aug 2023 11:28:10 +0530 Subject: [PATCH] checker: explicitly disallow creating type aliases of `none`, i.e. `type Abc = none` (#19078) --- vlib/v/checker/checker.v | 3 +++ vlib/v/checker/tests/type_alias_none_parent_type_err.out | 3 +++ vlib/v/checker/tests/type_alias_none_parent_type_err.vv | 1 + 3 files changed, 7 insertions(+) create mode 100644 vlib/v/checker/tests/type_alias_none_parent_type_err.out create mode 100644 vlib/v/checker/tests/type_alias_none_parent_type_err.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 46f128f9cf..5e0f0c0257 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -526,6 +526,9 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) { // type Sum = int | Alias // type Alias = Sum } + .none_ { + c.error('cannot create a type alias of `none` as it is a value', node.type_pos) + } // The rest of the parent symbol kinds are also allowed, since they are either primitive types, // that in turn do not allow recursion, or are abstract enough so that they can not be checked at comptime: else {} diff --git a/vlib/v/checker/tests/type_alias_none_parent_type_err.out b/vlib/v/checker/tests/type_alias_none_parent_type_err.out new file mode 100644 index 0000000000..fec00f0eec --- /dev/null +++ b/vlib/v/checker/tests/type_alias_none_parent_type_err.out @@ -0,0 +1,3 @@ +vlib/v/checker/tests/type_alias_none_parent_type_err.vv:1:13: error: cannot create a type alias of `none` as it is a value + 1 | type None = none + | ~~~~ diff --git a/vlib/v/checker/tests/type_alias_none_parent_type_err.vv b/vlib/v/checker/tests/type_alias_none_parent_type_err.vv new file mode 100644 index 0000000000..9820150613 --- /dev/null +++ b/vlib/v/checker/tests/type_alias_none_parent_type_err.vv @@ -0,0 +1 @@ +type None = none