Interface blocks no longer allow duplicate fields
bug: skia:12793 Change-Id: Idccdab5ee8f1c7792bdfe98efd379d0199a65377 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/492397 Reviewed-by: John Stiles <johnstiles@google.com> Commit-Queue: Julia Lavrova <jlavrova@google.com>
This commit is contained in:
parent
fc5fc658c8
commit
a856f40086
@ -2,3 +2,6 @@ IB {
|
||||
float f;
|
||||
float f;
|
||||
} ib;
|
||||
|
||||
IB1 { float f; };
|
||||
IB2 { float f; };
|
||||
|
@ -902,6 +902,7 @@ bool DSLParser::interfaceBlock(const dsl::DSLModifiers& modifiers) {
|
||||
}
|
||||
this->nextToken();
|
||||
SkTArray<dsl::Field> fields;
|
||||
std::unordered_set<String> field_names;
|
||||
while (!this->checkNext(Token::Kind::TK_RBRACE)) {
|
||||
DSLModifiers fieldModifiers = this->modifiers();
|
||||
skstd::optional<dsl::DSLType> type = this->type(&fieldModifiers);
|
||||
@ -927,8 +928,20 @@ bool DSLParser::interfaceBlock(const dsl::DSLModifiers& modifiers) {
|
||||
if (!this->expect(Token::Kind::TK_SEMICOLON, "';'")) {
|
||||
return false;
|
||||
}
|
||||
fields.push_back(dsl::Field(fieldModifiers, std::move(actualType),
|
||||
this->text(fieldName), this->position(fieldName)));
|
||||
|
||||
String key(this->text(fieldName));
|
||||
if (field_names.find(key) == field_names.end()) {
|
||||
fields.push_back(dsl::Field(fieldModifiers,
|
||||
std::move(actualType),
|
||||
this->text(fieldName),
|
||||
this->position(fieldName)));
|
||||
field_names.emplace(key);
|
||||
} else {
|
||||
this->error(typeName,
|
||||
"field '" + key +
|
||||
"' was already defined in the same interface block ('" +
|
||||
this->text(typeName) + "')");
|
||||
}
|
||||
}
|
||||
while (this->checkNext(Token::Kind::TK_COMMA));
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
### Compilation failed:
|
||||
|
||||
IB {
|
||||
float f;
|
||||
float f;
|
||||
} ib;
|
||||
error: 1: field 'f' was already defined in the same interface block ('IB')
|
||||
error: 7: symbol 'f' was already defined
|
||||
2 errors
|
||||
|
Loading…
Reference in New Issue
Block a user