mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:11:12 +01:00
Add signature enforcement for Main.Run and give it the symbol name main. (#3266)
For #2550.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "toolchain/check/context.h"
|
||||
#include "toolchain/check/convert.h"
|
||||
#include "toolchain/sem_ir/entry_point.h"
|
||||
|
||||
namespace Carbon::Check {
|
||||
|
||||
@@ -59,6 +60,21 @@ static auto BuildFunctionDeclaration(Context& context)
|
||||
auto decl_id = context.AddNode(
|
||||
SemIR::Node::FunctionDeclaration::Make(fn_node, function_id));
|
||||
context.declaration_name_stack().AddNameToLookup(name_context, decl_id);
|
||||
|
||||
if (SemIR::IsEntryPoint(context.semantics_ir(), function_id)) {
|
||||
// TODO: Update this once valid signatures for the entry point are decided.
|
||||
if (!context.semantics_ir().GetNodeBlock(param_refs_id).empty() ||
|
||||
(return_slot_id.is_valid() &&
|
||||
return_type_id !=
|
||||
context.CanonicalizeType(SemIR::NodeId::BuiltinBoolType) &&
|
||||
return_type_id != context.CanonicalizeTupleType(fn_node, {}))) {
|
||||
CARBON_DIAGNOSTIC(InvalidMainRunSignature, Error,
|
||||
"Invalid signature for `Main.Run` function. Expected "
|
||||
"`fn ()` or `fn () -> i32`.");
|
||||
context.emitter().Emit(fn_node, InvalidMainRunSignature);
|
||||
}
|
||||
}
|
||||
|
||||
return {function_id, decl_id};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user