mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 15:21:04 +01:00
Generic classes (#1124)
* start of generic classes * fix regressions * class functions in interfaces * access to class function on interface from class parameter * more stuff working for generic classes * fixing bugs * update TypeEqual for generic classes * fixing bugs and finding new ones * disable unqualified access to members from other members for now * minor edits * bug fixes * introduce compile_time_value to use in type checker instead of constant_value * cleanup * put a CHECK back in * failure test cases for the new FATAL_COMPILATION_ERROR * change a runtime FATAL into a FATAL_COMPILATION_ERROR * Update executable_semantics/ast/declaration.h Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/action_stack.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/interpreter.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/interpreter.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/resolve_names.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * responses to reviews * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * rename compile_time_value to symbolic_identity * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/type_checker.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Jon Meow <jperkins@google.com> * more edits from review * Apply suggestions from code review Co-authored-by: Geoff Romer <gromer@google.com> * review responses * Update executable_semantics/interpreter/interpreter.cpp Co-authored-by: Geoff Romer <gromer@google.com> * const impl_scope for TypeCheckChoiceDeclaration * add some const Co-authored-by: Jon Meow <jperkins@google.com> Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
Geoff Romer
parent
37a0e35b31
commit
210856dd57
@@ -178,6 +178,14 @@ static auto ResolveNames(Pattern& pattern, StaticScope& enclosing_scope)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PatternKind::GenericBinding: {
|
||||
auto& binding = cast<GenericBinding>(pattern);
|
||||
RETURN_IF_ERROR(ResolveNames(binding.type(), enclosing_scope));
|
||||
if (binding.name() != AnonymousName) {
|
||||
RETURN_IF_ERROR(enclosing_scope.Add(binding.name(), &binding));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PatternKind::TuplePattern:
|
||||
for (Nonnull<Pattern*> field : cast<TuplePattern>(pattern).fields()) {
|
||||
RETURN_IF_ERROR(ResolveNames(*field, enclosing_scope));
|
||||
@@ -315,8 +323,8 @@ static auto ResolveNames(Declaration& declaration, StaticScope& enclosing_scope)
|
||||
StaticScope function_scope;
|
||||
function_scope.AddParent(&enclosing_scope);
|
||||
for (Nonnull<GenericBinding*> binding : function.deduced_parameters()) {
|
||||
RETURN_IF_ERROR(function_scope.Add(binding->name(), binding));
|
||||
RETURN_IF_ERROR(ResolveNames(binding->type(), function_scope));
|
||||
RETURN_IF_ERROR(function_scope.Add(binding->name(), binding));
|
||||
}
|
||||
if (function.is_method()) {
|
||||
RETURN_IF_ERROR(ResolveNames(function.me_pattern(), function_scope));
|
||||
@@ -336,9 +344,17 @@ static auto ResolveNames(Declaration& declaration, StaticScope& enclosing_scope)
|
||||
StaticScope class_scope;
|
||||
class_scope.AddParent(&enclosing_scope);
|
||||
RETURN_IF_ERROR(class_scope.Add(class_decl.name(), &class_decl));
|
||||
for (Nonnull<Declaration*> member : class_decl.members()) {
|
||||
RETURN_IF_ERROR(AddExposedNames(*member, class_scope));
|
||||
if (class_decl.type_params().has_value()) {
|
||||
RETURN_IF_ERROR(ResolveNames(**class_decl.type_params(), class_scope));
|
||||
}
|
||||
|
||||
// TODO: Disable unqualified access of members by other members for now.
|
||||
// Put it back later, but in a way that turns unqualified accesses
|
||||
// into qualified ones, so that generic classes and impls
|
||||
// behave the in the right way. -Jeremy
|
||||
// for (Nonnull<Declaration*> member : class_decl.members()) {
|
||||
// AddExposedNames(*member, class_scope);
|
||||
// }
|
||||
for (Nonnull<Declaration*> member : class_decl.members()) {
|
||||
RETURN_IF_ERROR(ResolveNames(*member, class_scope));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user