Bug 26515

Summary: Array trim has invalid type
Product: poke Reporter: Mohammad-Reza Nabipoor <mnabipoor>
Component: defaultAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: jose.marchesi, poke-devel
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed: 2020-08-21 00:00:00

Description Mohammad-Reza Nabipoor 2020-08-21 07:56:50 UTC
Hi,

I think this behavior is counterintuitive:

(poke) defvar a = [1, 2, 3]
(poke) defvar b = [1, 2]
(poke) defvar c = a[0:1]
(poke) b
[1,2]
(poke) c
[1,2]
(poke) b == c
<stdin>:1:6: error: invalid operand
<stdin>:1:6: error: expected int<32>[2], got int<32>[3]
b == c;
     ^

Is this a design decision or just an implementation bug?


Thanks
Comment 1 Jose E. Marchesi 2020-08-21 08:37:32 UTC
Hi Mohammad.
Thanks for the report.

This looks like a bug.  The type of an array trim should be, generally, an unbounded array type having the same base type than the original array. So in:

defvar a = [1,2,3]
defvar b = a[0:1]

The type of `a' is int<32>[3]
The type of `b' is int<32>[]
Comment 2 Jose E. Marchesi 2020-08-21 09:35:13 UTC
This is fixed in master with commit

commit 3cca7544d54eb7e45e0e1fc1a160bc0263391ced (HEAD -> master, origin/master, origin/HEAD)
Author: Jose E. Marchesi <jose.marchesi@oracle.com>
Date:   Fri Aug 21 11:34:00 2020 +0200

    typify: the types of trimmed arrays are unbounded
    
    2020-08-21  Jose E. Marchesi  <jemarch@gnu.org>
    
            * libpoke/pkl-typify.c (pkl_typify1_ps_trimmer): The type of a
            trimmed array is unbounded.
            * testsuite/poke.pkl/trim-26.pk: New test.