Expect parentheses after an alternative only if they were present in its declaration (#2605)

The design of choice types expects the declaration of an alternative to match the usage: if an alternative is declared as `None`, then it should be used as `None` not `None()`, and if it is declared as `None()` then it should be used as `None()` not `None`. Update explorer to match.

Also clean up the handling of choice types and alternative values a little in general, by moving away from identifying choice types and alternatives as strings and towards identifying them symbolically.

Closes #2422
This commit is contained in:
Richard Smith
2023-02-14 13:28:52 -08:00
committed by GitHub
parent f7924aa93f
commit 59ff7743c0
18 changed files with 315 additions and 168 deletions
+14 -1
View File
@@ -429,11 +429,24 @@ auto ImplDeclaration::Create(Nonnull<Arena*> arena, SourceLocation source_loc,
}
void AlternativeSignature::Print(llvm::raw_ostream& out) const {
out << "alt " << name() << " " << signature();
out << "alt " << name();
if (auto sig = signature()) {
out << **signature();
}
}
void AlternativeSignature::PrintID(llvm::raw_ostream& out) const {
out << name();
}
auto ChoiceDeclaration::FindAlternative(std::string_view name) const
-> std::optional<const AlternativeSignature*> {
for (auto* alt : alternatives()) {
if (alt->name() == name) {
return alt;
}
}
return std::nullopt;
}
} // namespace Carbon