mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:41:27 +01:00
Initial support for associated constants (#1376)
Basic support for declaring, specifying the values of, and using associated constants. This is incomplete in various ways. For example, when checking whether a type satisfies a constraint, there is no check that its associated constants match those in the constraint, and name lookup into a value whose type is an associated constant is not supported yet. Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
4c90b4928e
commit
663ed32b1b
@@ -74,6 +74,11 @@ void Declaration::Print(llvm::raw_ostream& out) const {
|
||||
break;
|
||||
}
|
||||
|
||||
case DeclarationKind::AssociatedConstantDeclaration:
|
||||
PrintID(out);
|
||||
out << ";\n";
|
||||
break;
|
||||
|
||||
case DeclarationKind::SelfDeclaration: {
|
||||
out << "Self";
|
||||
break;
|
||||
@@ -130,6 +135,12 @@ void Declaration::PrintID(llvm::raw_ostream& out) const {
|
||||
break;
|
||||
}
|
||||
|
||||
case DeclarationKind::AssociatedConstantDeclaration: {
|
||||
const auto& let = cast<AssociatedConstantDeclaration>(*this);
|
||||
out << "let " << let.binding();
|
||||
break;
|
||||
}
|
||||
|
||||
case DeclarationKind::SelfDeclaration: {
|
||||
out << "Self";
|
||||
break;
|
||||
@@ -156,6 +167,8 @@ auto GetName(const Declaration& declaration)
|
||||
return cast<InterfaceDeclaration>(declaration).name();
|
||||
case DeclarationKind::VariableDeclaration:
|
||||
return cast<VariableDeclaration>(declaration).binding().name();
|
||||
case DeclarationKind::AssociatedConstantDeclaration:
|
||||
return cast<AssociatedConstantDeclaration>(declaration).binding().name();
|
||||
case DeclarationKind::ImplDeclaration:
|
||||
return std::nullopt;
|
||||
case DeclarationKind::SelfDeclaration:
|
||||
|
||||
Reference in New Issue
Block a user