mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-08 16:08:46 +00:00
part of match type check
This commit is contained in:
parent
63d0335188
commit
0da0c9f6f5
1 changed files with 56 additions and 1 deletions
|
|
@ -85,6 +85,61 @@ nodes::TypeCheckResult type_check_match(const nodes::Match &expression,
|
||||||
SourcesManager &sources_manager,
|
SourcesManager &sources_manager,
|
||||||
State &state,
|
State &state,
|
||||||
const Arguments &arguments) {
|
const Arguments &arguments) {
|
||||||
|
nodes::TypeCheckResult value_result = type_check_expression(
|
||||||
|
*expression.get_value(), sources_manager, state, {});
|
||||||
|
|
||||||
|
if (value_result.is_invalid()) {
|
||||||
|
sources_manager.get_error_log()->add_error(
|
||||||
|
error_handling::ErrorLog::ErrorMessage(
|
||||||
|
expression, "Match value is invalid",
|
||||||
|
error_handling::ErrorType::TYPE_CHECK));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<nodes::TypeCheckResult> expression_result;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < expression.cases_size(); ++i) {
|
||||||
|
const nodes::Match::Case *current_case = expression.get_case(i);
|
||||||
|
|
||||||
|
type_check_expression(
|
||||||
|
*current_case->get_value(), sources_manager, state,
|
||||||
|
Arguments{value_result.is_invalid() ? nodes::MaybeTypeProxy{}
|
||||||
|
: expression_result.value().get()
|
||||||
|
});
|
||||||
|
// TODO: work with case
|
||||||
|
// TODO: use type modifiers
|
||||||
|
|
||||||
|
if (current_case->get_condition().has_value()) {
|
||||||
|
type_check_expression(
|
||||||
|
*current_case->get_condition().value(), sources_manager, state,
|
||||||
|
Arguments::expect_builtin(builtin::types::Type::BOOL, sources_manager));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_case->get_expression().has_value()) {
|
||||||
|
nodes::TypeCheckResult case_result = type_check_expression(
|
||||||
|
*current_case->get_condition().value(), sources_manager, state,
|
||||||
|
Arguments{expression_result.has_value()
|
||||||
|
? expression_result.value().get()
|
||||||
|
: nodes::MaybeTypeProxy{}});
|
||||||
|
|
||||||
|
if (!expression_result.has_value() && !case_result.is_invalid()) {
|
||||||
|
expression_result = std::move(case_result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: if there is expression_result, it should be returned in all cases
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!expression_result.has_value()) {
|
||||||
|
expression_result = nodes::TypeCheckResult{
|
||||||
|
sources_manager.get_type_storage()->primitive_type(
|
||||||
|
builtin::types::Type::UNIT)};
|
||||||
|
}
|
||||||
|
|
||||||
|
return type_same_to_expected(sources_manager.get_type_storage()->add_array_of(
|
||||||
|
expression_result.value().get()),
|
||||||
|
arguments.expected_type, expression,
|
||||||
|
*sources_manager.get_error_log());
|
||||||
} // IN PROGRESS
|
} // IN PROGRESS
|
||||||
|
|
||||||
nodes::TypeCheckResult type_check_condition(const nodes::Condition &expression,
|
nodes::TypeCheckResult type_check_condition(const nodes::Condition &expression,
|
||||||
|
|
@ -135,7 +190,7 @@ nodes::TypeCheckResult type_check_condition(const nodes::Condition &expression,
|
||||||
expression_result.value().get()),
|
expression_result.value().get()),
|
||||||
arguments.expected_type, expression,
|
arguments.expected_type, expression,
|
||||||
*sources_manager.get_error_log());
|
*sources_manager.get_error_log());
|
||||||
} // IN PROGRESS
|
}
|
||||||
|
|
||||||
nodes::TypeCheckResult type_check_loop(const nodes::Loop &expression,
|
nodes::TypeCheckResult type_check_loop(const nodes::Loop &expression,
|
||||||
SourcesManager &sources_manager,
|
SourcesManager &sources_manager,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue