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

checker: check if struct field type isn't type (#15359)

This commit is contained in:
Swastik Baranwal 2022-08-06 21:41:51 +05:30 committed by GitHub
parent 8d9af2e4a1
commit d6b594c4e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -84,6 +84,10 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
struct_sym.info.is_heap = true struct_sym.info.is_heap = true
} }
} }
if sym.kind == .multi_return {
c.error('cannot use multi return as field type', field.type_pos)
}
if field.has_default_expr { if field.has_default_expr {
c.expected_type = field.typ c.expected_type = field.typ
default_expr_type := c.expr(field.default_expr) default_expr_type := c.expr(field.default_expr)

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/struct_multi_return_field_err.vv:2:16: error: cannot use multi return as field type
1 | struct Tuple{
2 | data (int, int)
| ^
3 | }
4 |

View File

@ -0,0 +1,8 @@
struct Tuple{
data (int, int)
}
fn main() {
x := Tuple{}
println(x)
}