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:
parent
72412a8672
commit
2f3891bf76
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user