Duplicate field names in struct

bug: skia:12712
Change-Id: I61a4512c10bf91d6396c38f148a714492669a9e0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/491820
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
This commit is contained in:
Julia Lavrova 2022-01-06 10:44:06 -05:00 committed by SkCQ
parent 72412a8672
commit 2f3891bf76
2 changed files with 19 additions and 6 deletions

View File

@ -618,6 +618,7 @@ skstd::optional<DSLType> DSLParser::structDeclaration() {
return skstd::nullopt;
}
SkTArray<DSLField> fields;
std::unordered_set<String> field_names;
while (!this->checkNext(Token::Kind::TK_RBRACE)) {
DSLModifiers modifiers = this->modifiers();
skstd::optional<DSLType> type = this->type(&modifiers);
@ -638,8 +639,21 @@ skstd::optional<DSLType> DSLParser::structDeclaration() {
return skstd::nullopt;
}
}
fields.push_back(DSLField(modifiers, std::move(actualType), this->text(memberName),
this->position(memberName)));
String key(this->text(memberName));
auto found = field_names.find(key);
if (found == field_names.end()) {
fields.push_back(DSLField(modifiers,
std::move(actualType),
this->text(memberName),
this->position(memberName)));
field_names.emplace(key);
} else {
this->error(name,
"field '" + key +
"' was already defined in the same struct ('" + this->text(name) +
"')");
}
} while (this->checkNext(Token::Kind::TK_COMMA));
if (!this->expect(Token::Kind::TK_SEMICOLON, "';'")) {
return skstd::nullopt;

View File

@ -1,5 +1,4 @@
### Compilation failed:
struct Varyings {
float var;
float var;
};
error: 1: field 'var' was already defined in the same struct ('Varyings')
1 error