From 7451999571f5874132a05a8593c827957ddec2a9 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 23 Oct 2026 13:18:34 +0100 Subject: [PATCH] conform: a const parameter's slice returned, of the caller's array and of a temporary used within the statement, as report 2026-10.36's 7.3 has it --- diff --git a/conform/run/ConstParamSlice.expect b/conform/run/ConstParamSlice.expect new file mode 100644 index 0000000..c789c41 --- /dev/null +++ b/conform/run/ConstParamSlice.expect @@ -0,0 +1,3 @@ +jello +temp +2 diff --git a/conform/run/ConstParamSlice.raz b/conform/run/ConstParamSlice.raz new file mode 100644 index 0000000..ad56d2f --- /dev/null +++ b/conform/run/ConstParamSlice.raz @@ -0,0 +1,35 @@ +(* A slice of a const parameter may be returned: it is the caller's + array, not the procedure's frame. Given a temporary, the slice lives + to the end of the caller's statement (report sections 7.3 and 8). *) +module ConstParamSlice; +import Out; + +type Line = record text: [8]U8; len: INT; end; + +var line: Line; + +proc used(const l: Line): []U8; +begin + return l.text[0..l.len]; +end; + +proc make(s: []U8): Line; +var l: Line; +begin + COPY(l.text, s); + l.len := LEN(s); + return l; +end; + +proc main*; +var s: []U8; +begin + line := make("hello"); + s := used(line); + line.text[0] := 'j'; + Out.str(s); Out.ln; (* the caller's array: jello *) + Out.str(used(make("temp"))); Out.ln; (* a temporary, read within the statement *) + Out.int(LEN(used({text: "abc", len: 2}))); Out.ln; +end; + +end ConstParamSlice. diff --git a/doc/compiler.md b/doc/compiler.md index c5d8460..cc3197c 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -1425,7 +1425,9 @@ The frame: an item's `frame` says, for an array or record, that it lies in the procedure's own frame (a local, a value parameter, which is a -copy even when passed by address, or a temporary), and for a slice, +copy even when passed by address, or a temporary; not a `var` or +`const` parameter, the caller's, even when that is a temporary of the +caller's statement), and for a slice, that it points there. `makeItem` and `tempItem` set it; `field` and `index` keep it for a part of the array, and drop it for an element of a slice or a slice kept in a field, which may point anywhere; `deref`