Bug 26515 - Array trim has invalid type
Summary: Array trim has invalid type
Status: RESOLVED FIXED
Alias: None
Product: poke
Classification: Unclassified
Component: Compiler (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-21 07:56 UTC by Mohammad-Reza Nabipoor
Modified: 2020-11-14 18:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-08-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.