aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-17 17:36:59 +0200
committerEugen Wissner <belka@caraus.de>2026-07-17 17:36:59 +0200
commit4f260c5e98def6bd1b3498d4085de5080cca7641 (patch)
tree89f80e6ffba1aa7a89702e40a3010a43b4639c08 /boot
parente676e74efbbbf62887b9442326399eebccc4d108 (diff)
downloadelna-4f260c5e98def6bd1b3498d4085de5080cca7641.tar.gz
Disallow "[n] const T"
Diffstat (limited to 'boot')
-rw-r--r--boot/name_analysis.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/boot/name_analysis.cc b/boot/name_analysis.cc
index cfc4e35..48251cd 100644
--- a/boot/name_analysis.cc
+++ b/boot/name_analysis.cc
@@ -51,8 +51,7 @@ namespace elna::boot
return "Symbol '" + identifier + "' has been already defined";
}
- std::optional<std::pair<std::string, source_position>>
- redefinition_error::note() const
+ std::optional<std::pair<std::string, source_position>> redefinition_error::note() const
{
if (original.has_value() && original->start().available())
{
@@ -61,6 +60,16 @@ namespace elna::boot
return std::nullopt;
}
+ const_array_error::const_array_error(const source_position position)
+ : error(position)
+ {
+ }
+
+ std::string const_array_error::what() const
+ {
+ return "const must be written before the array size, not after";
+ }
+
// Members of a constant aggregate are constant themselves.
static type qualify_member_type(const type& element, const type& aggregate)
{
@@ -176,9 +185,12 @@ namespace elna::boot
void name_analysis_visitor::visit(array_type_expression *expression)
{
walking_visitor::visit(expression);
- auto result_type = std::make_shared<array_type>(this->current_type, expression->size);
- this->current_type = type(result_type);
+ if (this->current_type.get<constant_type>() != nullptr)
+ {
+ add_error<const_array_error>(expression->position());
+ }
+ this->current_type = type(std::make_shared<array_type>(this->current_type, expression->size));
}
/**