Validate that the argument to __mix is a mixin. (#2757)

This commit is contained in:
Jon Ross-Perkins
2023-04-12 09:25:43 -07:00
committed by GitHub
parent 819c1745c7
commit 9245e17d4c
2 changed files with 24 additions and 1 deletions
+6 -1
View File
@@ -6129,7 +6129,12 @@ auto TypeChecker::DeclareDeclaration(Nonnull<Declaration*> d,
CARBON_ASSIGN_OR_RETURN(
Nonnull<const Value*> mixin,
InterpExp(&mix_decl.mixin(), arena_, trace_stream_));
mix_decl.set_mixin_value(cast<MixinPseudoType>(mixin));
if (const auto* mixin_value = dyn_cast<MixinPseudoType>(mixin)) {
mix_decl.set_mixin_value(mixin_value);
} else {
return ProgramError(mix_decl.source_loc())
<< "Not a valid mixin: `" << mix_decl.mixin() << "`";
}
const auto& mixin_decl = mix_decl.mixin_value().declaration();
if (!mixin_decl.is_declared()) {
return ProgramError(mix_decl.source_loc())
+18
View File
@@ -0,0 +1,18 @@
// 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
// RUN: %{not} %{explorer-run}
// RUN: %{not} %{explorer-run-trace}
package ExplorerTest api;
__mixin Mixin {
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/mixin/fail_mix_invalid.carbon:[[@LINE+1]]: Not a valid mixin: `()`
__mix ();
}
fn Main() -> i32 {
return 0;
}