diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index d5a26506c9..5c3269a757 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -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`') } diff --git a/vlib/v/tests/match_test.v b/vlib/v/tests/match_test.v index 71458872d1..32a77b6b1c 100644 --- a/vlib/v/tests/match_test.v +++ b/vlib/v/tests/match_test.v @@ -193,7 +193,9 @@ fn (a Alfa) letter() rune { struct Bravo { // A field so that Alfa and Bravo structures aren't the same dummy_field int - char rune = `b` +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` } fn (b Bravo) letter() rune {