From d2ce1f74d67d956100a1bf920a15736f2484335c Mon Sep 17 00:00:00 2001 From: spaceface Date: Wed, 18 Aug 2021 13:09:54 +0200 Subject: [PATCH] ast.table: fix aggregate field type equality check (#11210) --- vlib/v/ast/table.v | 7 ++++++- vlib/v/tests/match_test.v | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) 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 {