From abecb251851e4fb83a8144a31cfb5269ab71f554 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 20 Jun 2023 12:32:58 -0700 Subject: [PATCH] Fix a fuzzer-found crash. (#2930) The crash occurred because of an alias target of a mixin. While eventually, we should probably have some ability to alias mixins, this isn't yet setup in the explorer and doesn't seem like a current priority. We got here because the mixin type checking made it far enough to not reject this within the type checker, but the next step wasn't prepared for this to come out of the type checker. The simplest fix seems to be to reflect that it *can* escape the type checker, but still isn't (yet) a valid alias target. Test case added. --- explorer/interpreter/type_checker.cpp | 6 +++--- .../mixin/fail_mix_as_alias_target.carbon | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 explorer/testdata/mixin/fail_mix_as_alias_target.carbon diff --git a/explorer/interpreter/type_checker.cpp b/explorer/interpreter/type_checker.cpp index 5e06209a968d..db0569bb714c 100644 --- a/explorer/interpreter/type_checker.cpp +++ b/explorer/interpreter/type_checker.cpp @@ -6168,7 +6168,6 @@ static auto IsValidTypeForAliasTarget(Nonnull type) -> bool { case Value::Kind::StructValue: case Value::Kind::NominalClassValue: case Value::Kind::MixinPseudoType: - case Value::Kind::TypeOfMixinPseudoType: case Value::Kind::AlternativeValue: case Value::Kind::TupleValue: case Value::Kind::ImplWitness: @@ -6182,11 +6181,11 @@ static auto IsValidTypeForAliasTarget(Nonnull type) -> bool { case Value::Kind::AlternativeConstructorValue: case Value::Kind::StringValue: case Value::Kind::UninitializedValue: - CARBON_FATAL() << "type of alias target is not a type"; + CARBON_FATAL() << "type of alias target is not a type: " << *type; case Value::Kind::AutoType: case Value::Kind::VariableType: - CARBON_FATAL() << "pattern type in alias target"; + CARBON_FATAL() << "pattern type in alias target: " << *type; case Value::Kind::IntType: case Value::Kind::BoolType: @@ -6198,6 +6197,7 @@ static auto IsValidTypeForAliasTarget(Nonnull type) -> bool { case Value::Kind::ChoiceType: case Value::Kind::StringType: case Value::Kind::AssociatedConstant: + case Value::Kind::TypeOfMixinPseudoType: return false; case Value::Kind::FunctionType: diff --git a/explorer/testdata/mixin/fail_mix_as_alias_target.carbon b/explorer/testdata/mixin/fail_mix_as_alias_target.carbon new file mode 100644 index 000000000000..7297be1d68f7 --- /dev/null +++ b/explorer/testdata/mixin/fail_mix_as_alias_target.carbon @@ -0,0 +1,16 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE + +package ExplorerTest api; + +__mixin Operations {} + +// CHECK:STDERR: COMPILATION ERROR: fail_mix_as_alias_target.carbon:[[@LINE+1]]: invalid target for alias declaration +alias OperationsAlias = Operations; + +fn Main() -> i32 { + return 0; +}