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

ast.table: fix aggregate field type equality check (#11210)

This commit is contained in:
spaceface 2021-08-18 13:09:54 +02:00 committed by GitHub
parent eee71cebd4
commit d2ce1f74d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -412,9 +412,14 @@ fn (t &Table) register_aggregate_field(mut sym TypeSymbol, name string) ?StructF
if !found_once {
found_once = true
new_field = type_field
} else if !new_field.equals(type_field) {
} else if new_field.typ != type_field.typ {
return error('field `${t.type_to_str(typ)}.$name` type is different')
}
new_field = StructField{
...new_field
is_mut: new_field.is_mut && type_field.is_mut
is_pub: new_field.is_pub && type_field.is_pub
}
} else {
return error('type `${t.type_to_str(typ)}` has no field or method `$name`')
}

View File

@ -193,6 +193,8 @@ fn (a Alfa) letter() rune {
struct Bravo {
// A field so that Alfa and Bravo structures aren't the same
dummy_field int
pub mut:
// NB: the `char` field is not `pub` or `mut` in all sumtype variants, but using it in aggregates should still work
char rune = `b`
}