diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index dc58640eb8..b5d85e0e03 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -35,10 +35,6 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) { } } for i, field in node.fields { - if field.typ == ast.any_type { - c.error('struct field cannot be the `any` type, use generics instead', - field.type_pos) - } c.ensure_type_exists(field.typ, field.type_pos) or { return } if field.typ.has_flag(.generic) { has_generic_types = true diff --git a/vlib/v/checker/tests/struct_field_with_any_type_err.out b/vlib/v/checker/tests/struct_field_with_any_type_err.out index ae9e972f13..067cc7342a 100644 --- a/vlib/v/checker/tests/struct_field_with_any_type_err.out +++ b/vlib/v/checker/tests/struct_field_with_any_type_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/struct_field_with_any_type_err.vv:2:6: error: struct field cannot be the `any` type, use generics instead +vlib/v/checker/tests/struct_field_with_any_type_err.vv:2:6: error: cannot use `any` type here, `any` will be implemented in V 0.4 1 | struct My_type { 2 | fld any | ~~~ diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index a90adf14cb..e59e8d015c 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -607,6 +607,12 @@ pub fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_d 'int_literal' { ret = ast.int_literal_type } + 'any' { + if p.file_backend_mode != .js && p.mod != 'builtin' { + p.error('cannot use `any` type here, `any` will be implemented in V 0.4') + } + ret = ast.any_type + } else { p.next() if name.len == 1 && name[0].is_capital() { diff --git a/vlib/v/parser/tests/cast_to_any_type_err.out b/vlib/v/parser/tests/cast_to_any_type_err.out new file mode 100644 index 0000000000..15de454e22 --- /dev/null +++ b/vlib/v/parser/tests/cast_to_any_type_err.out @@ -0,0 +1,6 @@ +vlib/v/parser/tests/cast_to_any_type_err.vv:2:7: error: cannot use `any` type here, `any` will be implemented in V 0.4 + 1 | fn main() { + 2 | a := any(22) + | ~~~ + 3 | println(a) + 4 | } diff --git a/vlib/v/parser/tests/cast_to_any_type_err.vv b/vlib/v/parser/tests/cast_to_any_type_err.vv new file mode 100644 index 0000000000..7bd9aad2a6 --- /dev/null +++ b/vlib/v/parser/tests/cast_to_any_type_err.vv @@ -0,0 +1,4 @@ +fn main() { + a := any(22) + println(a) +}