diff options
Diffstat (limited to 'boot/type_check.cc')
| -rw-r--r-- | boot/type_check.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/boot/type_check.cc b/boot/type_check.cc index 07deb2d..529f66a 100644 --- a/boot/type_check.cc +++ b/boot/type_check.cc @@ -165,6 +165,11 @@ namespace elna::boot return "Type '" + this->actual.to_string() + "' cannot be converted to '" + payload.target.to_string() + "'"; } + else if constexpr (std::is_same_v<T, integer_literal_overflow>) + { + return "The number " + payload.overflow.to_string() + + " does not fit into the type '" + actual.to_string() + "'"; + } else if constexpr (std::is_same_v<T, kind>) { switch (payload) @@ -762,6 +767,17 @@ namespace elna::boot void type_analysis_visitor::visit(slicing_expression *expression) { walking_visitor::visit(expression); + + if (!is_integral_type(resolve_underlying_type(expression->start().type_decoration))) + { + add_error<type_mismatch_error>(expression->start().position(), + expression->start().type_decoration, type_mismatch_error::kind::array_index); + } + if (!is_integral_type(resolve_underlying_type(expression->end().type_decoration))) + { + add_error<type_mismatch_error>(expression->end().position(), + expression->end().type_decoration, type_mismatch_error::kind::array_index); + } } void type_analysis_visitor::visit(array_access_expression *expression) @@ -1008,4 +1024,22 @@ namespace elna::boot } } } + + void type_analysis_visitor::visit(literal<integer_literal> *expression) + { + bool narrowed{ false }; + if (expression->value.is_signed()) + { + narrowed = expression->value.fit_into(target.int_properties.size); + } + else + { + narrowed = expression->value.fit_into(target.word_properties.size); + } + if (!narrowed) + { + add_error<type_mismatch_error>(expression->position(), expression->type_decoration, + type_mismatch_error::integer_literal_overflow{ expression->value }); + } + } } |
