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
| @@ -0,0 +1,3 @@ | ||
| 1 | +jello | |
| 2 | +temp | |
| 3 | +2 |
| @@ -0,0 +1,35 @@ | ||
| 1 | +(* A slice of a const parameter may be returned: it is the caller's | |
| 2 | + array, not the procedure's frame. Given a temporary, the slice lives | |
| 3 | + to the end of the caller's statement (report sections 7.3 and 8). *) | |
| 4 | +module ConstParamSlice; | |
| 5 | +import Out; | |
| 6 | + | |
| 7 | +type Line = record text: [8]U8; len: INT; end; | |
| 8 | + | |
| 9 | +var line: Line; | |
| 10 | + | |
| 11 | +proc used(const l: Line): []U8; | |
| 12 | +begin | |
| 13 | + return l.text[0..l.len]; | |
| 14 | +end; | |
| 15 | + | |
| 16 | +proc make(s: []U8): Line; | |
| 17 | +var l: Line; | |
| 18 | +begin | |
| 19 | + COPY(l.text, s); | |
| 20 | + l.len := LEN(s); | |
| 21 | + return l; | |
| 22 | +end; | |
| 23 | + | |
| 24 | +proc main*; | |
| 25 | +var s: []U8; | |
| 26 | +begin | |
| 27 | + line := make("hello"); | |
| 28 | + s := used(line); | |
| 29 | + line.text[0] := 'j'; | |
| 30 | + Out.str(s); Out.ln; (* the caller's array: jello *) | |
| 31 | + Out.str(used(make("temp"))); Out.ln; (* a temporary, read within the statement *) | |
| 32 | + Out.int(LEN(used({text: "abc", len: 2}))); Out.ln; | |
| 33 | +end; | |
| 34 | + | |
| 35 | +end ConstParamSlice. |
| @@ -1425,7 +1425,9 @@ | ||
| 1425 | 1425 | |
| 1426 | 1426 | The frame: an item's `frame` says, for an array or record, that it lies |
| 1427 | 1427 | in the procedure's own frame (a local, a value parameter, which is a |
| 1428 | -copy even when passed by address, or a temporary), and for a slice, | |
| 1428 | +copy even when passed by address, or a temporary; not a `var` or | |
| 1429 | +`const` parameter, the caller's, even when that is a temporary of the | |
| 1430 | +caller's statement), and for a slice, | |
| 1429 | 1431 | that it points there. `makeItem` and `tempItem` set it; `field` and |
| 1430 | 1432 | `index` keep it for a part of the array, and drop it for an element of |
| 1431 | 1433 | a slice or a slice kept in a field, which may point anywhere; `deref` |