mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-01 22:02:45 +01:00
Tuple restrictions (#486)
* implement tuple restrictions: (1) named fields after positional, (2) order matters * after_named_member => seen_named_member
This commit is contained in:
@@ -339,13 +339,12 @@ auto TypeEqual(const Value* t1, const Value* t2) -> bool {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < t1->u.tuple.elts->size(); ++i) {
|
||||
std::optional<Address> t2_field =
|
||||
FindTupleField((*t1->u.tuple.elts)[i].first, t2);
|
||||
if (t2_field == std::nullopt) {
|
||||
if ((*t1->u.tuple.elts)[i].first != (*t2->u.tuple.elts)[i].first) {
|
||||
return false;
|
||||
}
|
||||
if (!TypeEqual(state->ReadFromMemory((*t1->u.tuple.elts)[i].second, 0),
|
||||
state->ReadFromMemory(*t2_field, 0))) {
|
||||
if (!TypeEqual(
|
||||
state->ReadFromMemory((*t1->u.tuple.elts)[i].second, 0),
|
||||
state->ReadFromMemory((*t2->u.tuple.elts)[i].second, 0))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -354,9 +353,13 @@ auto TypeEqual(const Value* t1, const Value* t2) -> bool {
|
||||
case ValKind::IntTV:
|
||||
case ValKind::BoolTV:
|
||||
case ValKind::ContinuationTV:
|
||||
case ValKind::TypeTV:
|
||||
return true;
|
||||
default:
|
||||
std::cerr << "TypeEqual used to compare non-type values" << std::endl;
|
||||
PrintValue(t1, std::cerr);
|
||||
std::cerr << std::endl;
|
||||
PrintValue(t2, std::cerr);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user