mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 09:11:05 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user