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:
Richard Smith
2022-07-14 18:18:27 -07:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 4c90b4928e
commit 663ed32b1b
40 changed files with 1454 additions and 291 deletions
+13
View File
@@ -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: