part of name expession type check plan

This commit is contained in:
programsnail 2024-04-06 14:04:15 +03:00
parent d6a3ce1946
commit f688dd99a2
3 changed files with 57 additions and 12 deletions

View file

@ -543,7 +543,45 @@ type_check_name_expression(const nodes::NameExpression &expression,
// TODO: constraints ??
const auto name = expression.get_name();
for (size_t i = 0; i < /*fragments_count*/; ++i) { // go in prefixes and try to find matching var name
{
const auto fragments = name->get_fragments();
nodes::Identifier current_prefix = fragments.front();
std::optional<State::VariableInfo> maybe_variable;
size_t i = 0;
for (; i < fragments.size(); ++i) { // go in prefixes and try to find matching var namei
if (i > 0) {
current_prefix.append_after(fragments[i]);
}
maybe_variable = state.find_variable(*current_prefix.get());
if (maybe_variable.has_value()) {
break;
}
}
if (maybe_variable.has_value()) {
auto& type = maybe_variable.value().type;
for (size_t j = i + 1; j < fragments.size(); ++i) {
// TODO: switch by type types: Variant, Tuple, ...
// Tuple -> try to find field
// Others -> try to open / builtin fields ?
const auto maybe_field = type.get()->get_parameter_proxy_by_name(*fragments[j].get());
if (maybe_field.has_value()) {
type = maybe_field.value();
continue;
}
if (j + 1 == fragments.size()) { // then this can be method call
// TODO: try to fond method or local function
}
// fields for the names should be found
// last segment can be function name
}
}
}
// --- TODO --- deal with passed type --- TODO --- (additional argument)