diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c3429549c5..79f5a53b17 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -462,6 +462,10 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) { } c.ensure_type_exists(node.parent_type, node.type_pos) or { return } mut parent_typ_sym := c.table.sym(node.parent_type) + if node.parent_type.has_flag(.result) { + c.add_error_detail('Result types cannot be stored and have to be unwrapped immediately') + c.error('cannot make an alias of Result type', node.type_pos) + } match parent_typ_sym.kind { .placeholder, .int_literal, .float_literal { c.error('unknown aliased type `${parent_typ_sym.name}`', node.type_pos) diff --git a/vlib/v/checker/tests/result_alias_type_err.out b/vlib/v/checker/tests/result_alias_type_err.out new file mode 100644 index 0000000000..f1d01a2a64 --- /dev/null +++ b/vlib/v/checker/tests/result_alias_type_err.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/result_alias_type_err.vv:1:12: error: cannot make an alias of Result type + 1 | type Abc = !int + | ~~~~ + 2 | + 3 | dump(Abc(5)) +Details: Result types cannot be stored and have to be unwrapped immediately diff --git a/vlib/v/checker/tests/result_alias_type_err.vv b/vlib/v/checker/tests/result_alias_type_err.vv new file mode 100644 index 0000000000..6cbf803290 --- /dev/null +++ b/vlib/v/checker/tests/result_alias_type_err.vv @@ -0,0 +1,3 @@ +type Abc = !int + +dump(Abc(5))