aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-09-08 21:14:03 +0200
committerEugen Wissner <belka@caraus.de>2026-09-08 21:14:03 +0200
commitb27872d5c5bfecae74195771f5c1f4e73385b6d6 (patch)
treed0bc9d09c5b4073a42680f07a8aa3dca8df9e50b
parent47c8f99b6ef812dbc22ca56a39ba21bccad47796 (diff)
downloadelna-b27872d5c5bfecae74195771f5c1f4e73385b6d6.tar.gz
Fix ICE with offset trait and non-type identifier
-rw-r--r--boot/type_check.cc16
-rw-r--r--testsuite/fail_compilation/offset_not_record.elna9
2 files changed, 24 insertions, 1 deletions
diff --git a/boot/type_check.cc b/boot/type_check.cc
index ab22a1c..5078da1 100644
--- a/boot/type_check.cc
+++ b/boot/type_check.cc
@@ -17,6 +17,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/type_check.h"
#include "elna/boot/evaluator.h"
+#include "elna/boot/name_analysis.h"
#include <ranges>
#include <utility>
@@ -1738,7 +1739,20 @@ namespace elna::boot
add_error<trait_error>(trait->name.position(), trait->name.name(),
trait_error::unsupported_type{ trait->types.front() });
}
- else if (trait->arguments.at(1)->is_named() == nullptr)
+ else if (auto *field = trait->arguments.at(1)->is_named())
+ {
+ if (erase_generic(trait->types.front()).get<record_type>() == nullptr)
+ {
+ add_error<trait_error>(trait->name.position(), trait->name.name(),
+ trait_error::unsupported_type{ trait->types.front() });
+ }
+ else if (lookup_field(trait->types.front(), field->name).empty())
+ {
+ add_error<member_error>(field->position(), field->name,
+ trait->types.front(), member_error::kind::not_found);
+ }
+ }
+ else
{
add_error<trait_error>(trait->arguments.at(1)->position(), trait->name.name(),
trait_error::offset_not_field_name{});
diff --git a/testsuite/fail_compilation/offset_not_record.elna b/testsuite/fail_compilation/offset_not_record.elna
new file mode 100644
index 0000000..d19e608
--- /dev/null
+++ b/testsuite/fail_compilation/offset_not_record.elna
@@ -0,0 +1,9 @@
+var
+ n: Word
+
+program()
+begin
+ n := #offset(Int, top) (* @Error Type 'Int' does not support trait '#offset' *)
+return 0u8
+
+end.