check_no_pass_type_in_argumets func

This commit is contained in:
ProgramSnail 2024-02-17 00:11:54 +03:00
parent 1a9408c2f6
commit ed4b984b81
3 changed files with 18 additions and 1 deletions

View file

@ -229,4 +229,8 @@ find_name_definition_handle_errors(const std::string &name,
void type_check_error(const std::string &message, const nodes::Node &node,
SourcesManager &sources_manager);
bool check_no_pass_type_in_arguments(const Arguments &arguments,
const nodes::Node &node,
SourcesManager &sources_manager);
} // namespace type_check

View file

@ -545,6 +545,8 @@ nodes::TypeCheckResult
type_check_constructor(const nodes::Constructor &expression,
SourcesManager &sources_manager, State &state,
const Arguments &arguments) {
check_no_pass_type_in_arguments(arguments, expression, sources_manager);
const auto maybe_type_definition = find_type_definition_handle_errors(
*expression.get_type()->get_name()->get(), expression, sources_manager);
if (!maybe_type_definition.has_value()) {
@ -620,7 +622,7 @@ nodes::TypeCheckResult type_check_lambda(const nodes::Lambda &expression,
// auto returned_type = type_check_expression(
// *expression.get_expression(), sources_manager, state, Arguments{});
return nodes::TypeCheckResult{expected_type};
return nodes::TypeCheckResult{expected_type}; // TODO: same to expected ??
} // IN PROGRESS
} // namespace type_check

View file

@ -72,4 +72,15 @@ void type_check_error(const std::string &message, const nodes::Node &node,
node, message, error_handling::ErrorType::TYPE_CHECK));
}
bool check_no_pass_type_in_arguments(const Arguments &arguments,
const nodes::Node &node,
SourcesManager &sources_manager) {
if (arguments.get_passed().has_value()) {
type_check_error("Type can't be passed to this node", node,
sources_manager);
return false;
}
return true;
}
} // namespace type_check