mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:21:21 +01:00
Validate that the argument to __mix is a mixin. (#2757)
This commit is contained in:
@@ -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
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user