|
|
@@ -817,20 +817,21 @@ auto TypeChecker::ExpectNonPlaceholderType(SourceLocation source_loc,
|
|
|
if (!IsPlaceholderType(type)) {
|
|
|
return Success();
|
|
|
}
|
|
|
- if (auto* member_name = dyn_cast<TypeOfMemberName>(type)) {
|
|
|
+ if (const auto* member_name = dyn_cast<TypeOfMemberName>(type)) {
|
|
|
return ProgramError(source_loc)
|
|
|
<< *member_name << " can only be used in a member access or alias";
|
|
|
}
|
|
|
- if (auto* param_entity = dyn_cast<TypeOfParameterizedEntityName>(type)) {
|
|
|
+ if (const auto* param_entity =
|
|
|
+ dyn_cast<TypeOfParameterizedEntityName>(type)) {
|
|
|
return ProgramError(source_loc)
|
|
|
<< "'" << param_entity->name() << "' must be given an argument list";
|
|
|
}
|
|
|
- if (auto* mixin_type = dyn_cast<TypeOfMixinPseudoType>(type)) {
|
|
|
+ if (const auto* mixin_type = dyn_cast<TypeOfMixinPseudoType>(type)) {
|
|
|
return ProgramError(source_loc)
|
|
|
<< "invalid use of mixin "
|
|
|
<< mixin_type->mixin_type().declaration().name();
|
|
|
}
|
|
|
- if (auto* namespace_type = dyn_cast<TypeOfNamespaceName>(type)) {
|
|
|
+ if (const auto* namespace_type = dyn_cast<TypeOfNamespaceName>(type)) {
|
|
|
return ProgramError(source_loc)
|
|
|
<< "expected `.member_name` after name of " << *namespace_type;
|
|
|
}
|
|
|
@@ -1320,7 +1321,7 @@ static auto LookupRewrite(llvm::ArrayRef<RewriteConstraint> rewrites,
|
|
|
return std::nullopt;
|
|
|
}
|
|
|
|
|
|
- for (auto& rewrite : rewrites) {
|
|
|
+ for (const auto& rewrite : rewrites) {
|
|
|
if (ValueEqual(interface, &rewrite.constant->interface(), std::nullopt) &&
|
|
|
member == &rewrite.constant->constant()) {
|
|
|
// A ConstraintType can only have one rewrite per (interface, member)
|
|
|
@@ -1596,7 +1597,7 @@ class TypeChecker::ConstraintTypeBuilder {
|
|
|
// Add all of the new constraints.
|
|
|
impl_scope->Add(new_impl_constraints, std::nullopt, std::nullopt,
|
|
|
GetSelfWitness(), type_checker);
|
|
|
- for (auto& equal : new_equality_constraints) {
|
|
|
+ for (const auto& equal : new_equality_constraints) {
|
|
|
impl_scope->AddEqualityConstraint(arena_->New<EqualityConstraint>(equal));
|
|
|
}
|
|
|
}
|
|
|
@@ -1670,7 +1671,7 @@ class TypeChecker::ConstraintTypeBuilder {
|
|
|
if (auto existing_rewrite = LookupRewrite(
|
|
|
new_rewrite_constraints, &rewrite_a.constant->interface(),
|
|
|
&rewrite_a.constant->constant())) {
|
|
|
- auto& rewrite_b = **existing_rewrite;
|
|
|
+ const auto& rewrite_b = **existing_rewrite;
|
|
|
if (ValueEqual(rewrite_a.unconverted_replacement,
|
|
|
rewrite_b.unconverted_replacement, std::nullopt) &&
|
|
|
TypeEqual(rewrite_a.unconverted_replacement_type,
|
|
|
@@ -1886,7 +1887,7 @@ auto TypeChecker::Substitute(const Bindings& bindings,
|
|
|
return type;
|
|
|
}
|
|
|
|
|
|
- auto* result = SubstituteImpl(bindings, type);
|
|
|
+ const auto* result = SubstituteImpl(bindings, type);
|
|
|
|
|
|
if (trace_stream_) {
|
|
|
**trace_stream_ << "substitution of {";
|
|
|
@@ -1923,7 +1924,7 @@ class TypeChecker::SubstituteTransform
|
|
|
-> Nonnull<const Value*> {
|
|
|
auto it = bindings_.args().find(&var_type->binding());
|
|
|
if (it == bindings_.args().end()) {
|
|
|
- if (auto& trace_stream = type_checker_->trace_stream_) {
|
|
|
+ if (const auto& trace_stream = type_checker_->trace_stream_) {
|
|
|
**trace_stream << "substitution: no value for binding " << *var_type
|
|
|
<< ", leaving alone\n";
|
|
|
}
|
|
|
@@ -1938,7 +1939,7 @@ class TypeChecker::SubstituteTransform
|
|
|
-> Nonnull<const Value*> {
|
|
|
auto it = bindings_.witnesses().find(witness->binding());
|
|
|
if (it == bindings_.witnesses().end()) {
|
|
|
- if (auto& trace_stream = type_checker_->trace_stream_) {
|
|
|
+ if (const auto& trace_stream = type_checker_->trace_stream_) {
|
|
|
**trace_stream << "substitution: no value for binding " << *witness
|
|
|
<< ", leaving alone\n";
|
|
|
}
|
|
|
@@ -2019,7 +2020,7 @@ class TypeChecker::SubstituteTransform
|
|
|
} else {
|
|
|
type_of_type = type_checker_->arena_->New<TypeType>();
|
|
|
}
|
|
|
- if (auto& trace_stream = type_checker_->trace_stream_) {
|
|
|
+ if (const auto& trace_stream = type_checker_->trace_stream_) {
|
|
|
**trace_stream << "substitution: self of constraint " << *constraint
|
|
|
<< " is substituted, new type of type is "
|
|
|
<< *type_of_type << "\n";
|
|
|
@@ -2034,7 +2035,7 @@ class TypeChecker::SubstituteTransform
|
|
|
builder.GetSelfWitness(), bindings_,
|
|
|
/*add_lookup_contexts=*/true);
|
|
|
Nonnull<const ConstraintType*> new_constraint = std::move(builder).Build();
|
|
|
- if (auto& trace_stream = type_checker_->trace_stream_) {
|
|
|
+ if (const auto& trace_stream = type_checker_->trace_stream_) {
|
|
|
**trace_stream << "substitution: " << *constraint << " => "
|
|
|
<< *new_constraint << "\n";
|
|
|
}
|
|
|
@@ -2063,7 +2064,7 @@ auto TypeChecker::RefineWitness(Nonnull<const Witness*> witness,
|
|
|
// See if this is already resolved as some number of layers of
|
|
|
// ConstraintImplWitness applied to an ImplWitness.
|
|
|
Nonnull<const Witness*> inner_witness = witness;
|
|
|
- while (auto* inner_constraint_impl_witness =
|
|
|
+ while (const auto* inner_constraint_impl_witness =
|
|
|
dyn_cast<ConstraintImplWitness>(inner_witness)) {
|
|
|
inner_witness = inner_constraint_impl_witness->constraint_witness();
|
|
|
}
|
|
|
@@ -2366,7 +2367,7 @@ auto TypeChecker::LookupRewriteInTypeOf(
|
|
|
// interface, member);
|
|
|
// where we substitute as little as possible to try to avoid infinite
|
|
|
// recursion.
|
|
|
- if (auto* constraint =
|
|
|
+ if (const auto* constraint =
|
|
|
dyn_cast<ConstraintType>(&assoc_const->constant().static_type())) {
|
|
|
for (auto rewrite : constraint->rewrite_constraints()) {
|
|
|
if (&rewrite.constant->constant() != &assoc_const->constant()) {
|
|
|
@@ -2425,7 +2426,7 @@ static auto IsInstanceMember(Nonnull<const Element*> element) {
|
|
|
case ElementKind::PositionalElement:
|
|
|
return true;
|
|
|
case ElementKind::NamedElement:
|
|
|
- const auto nom_element = cast<NamedElement>(element);
|
|
|
+ const auto* const nom_element = cast<NamedElement>(element);
|
|
|
if (!nom_element->declaration()) {
|
|
|
// This is a struct field.
|
|
|
return true;
|
|
|
@@ -2671,7 +2672,8 @@ auto TypeChecker::TypeCheckExp(Nonnull<Expression*> e,
|
|
|
access.set_is_type_access(!IsInstanceMember(&access.member()));
|
|
|
access.set_static_type(inst_member_type);
|
|
|
|
|
|
- if (auto* func_decl = dyn_cast<FunctionDeclaration>(result.member)) {
|
|
|
+ if (const auto* func_decl =
|
|
|
+ dyn_cast<FunctionDeclaration>(result.member)) {
|
|
|
CARBON_RETURN_IF_ERROR(
|
|
|
CheckAddrMeAccess(&access, func_decl, bindings, impl_scope));
|
|
|
}
|
|
|
@@ -4106,8 +4108,8 @@ auto TypeChecker::TypeCheckGenericBinding(GenericBinding& binding,
|
|
|
|
|
|
// Get the builtin interface that should be used for the given kind of
|
|
|
// assignment operator.
|
|
|
-static Builtins::Builtin GetBuiltinInterfaceForAssignOperator(
|
|
|
- AssignOperator op) {
|
|
|
+static auto GetBuiltinInterfaceForAssignOperator(AssignOperator op)
|
|
|
+ -> Builtins::Builtin {
|
|
|
switch (op) {
|
|
|
case AssignOperator::Plain:
|
|
|
return Builtins::AssignWith;
|
|
|
@@ -5051,7 +5053,8 @@ auto TypeChecker::DeclareConstraintTypeDeclaration(
|
|
|
// constraint for the constraint type: `let X:! Interface` adds a
|
|
|
// `Self.X is Interface` constraint that `impl`s must satisfy and users
|
|
|
// of the constraint type can rely on.
|
|
|
- if (auto* constraint_type = dyn_cast<ConstraintType>(constraint)) {
|
|
|
+ if (const auto* constraint_type =
|
|
|
+ dyn_cast<ConstraintType>(constraint)) {
|
|
|
builder.AddAndSubstitute(*this, constraint_type, assoc_value,
|
|
|
builder.GetSelfWitness(), Bindings(),
|
|
|
/*add_lookup_contexts=*/false);
|