1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: explicitly disallow creating type aliases of none, i.e. type Abc = none (#19078)

This commit is contained in:
Swastik Baranwal 2023-08-08 11:28:10 +05:30 committed by GitHub
parent 286d39706b
commit 8db1aaafd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -526,6 +526,9 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
// type Sum = int | Alias // type Sum = int | Alias
// type Alias = Sum // 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, // 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: // that in turn do not allow recursion, or are abstract enough so that they can not be checked at comptime:
else {} else {}

View File

@ -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
| ~~~~

View File

@ -0,0 +1 @@
type None = none