From 6301c1f2f669b84a429e836888629873721e7219 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 24 Jul 2026 18:40:04 +0200 Subject: Handle array and slice field constness --- boot/name_analysis.cc | 5 +++-- testsuite/fail_compilation/assign_array_length.elna | 7 +++++++ testsuite/fail_compilation/assign_slice_ptr.elna | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 testsuite/fail_compilation/assign_array_length.elna create mode 100644 testsuite/fail_compilation/assign_slice_ptr.elna diff --git a/boot/name_analysis.cc b/boot/name_analysis.cc index 0d25039..1e224da 100644 --- a/boot/name_analysis.cc +++ b/boot/name_analysis.cc @@ -209,11 +209,12 @@ namespace elna::boot { if (field_name == "length") { - return lookup_primitive_type("Word"); + return type(std::make_shared(lookup_primitive_type("Word"))); } if (field_name == "ptr") { - return type(std::make_shared(element_type)); + auto pointer = type(std::make_shared(element_type)); + return type(std::make_shared(pointer)); } return std::nullopt; } diff --git a/testsuite/fail_compilation/assign_array_length.elna b/testsuite/fail_compilation/assign_array_length.elna new file mode 100644 index 0000000..ac8f9df --- /dev/null +++ b/testsuite/fail_compilation/assign_array_length.elna @@ -0,0 +1,7 @@ +var + slice: []Int + array: [2]Int + +begin + array.length := slice.length (* @Error Cannot assign to a value of type 'const Word', because it is constant or contains constant members *) +end. diff --git a/testsuite/fail_compilation/assign_slice_ptr.elna b/testsuite/fail_compilation/assign_slice_ptr.elna new file mode 100644 index 0000000..aa7a379 --- /dev/null +++ b/testsuite/fail_compilation/assign_slice_ptr.elna @@ -0,0 +1,7 @@ +var + slice: []Int + array: [2]Int + +begin + slice.ptr := array.ptr (* @Error Cannot assign to a value of type 'const \^Int', because it is constant or contains constant members *) +end. -- cgit v1.2.3