Open stoneface86 opened 2 months ago
This should not be allowed by the compiler, the types are not compatible.
There is a type bug here. Even if one corrects the arrays, incorrect C is generated unless one explicitly converts to a type alias.
type
ChannelId = enum
ch1, ch2, ch3, ch4
OrderRow = array[ChannelId, uint8]
Order = seq[OrderRow]
let order = @[ [ch1: 0u8, 0, 0, 0], [ch1: 1u8, 1, 1, 1] ]#.Order # Explicitly converting stops the cgen error
static: assert order is Order
proc test(_: Order) = discard
test(order)
Description
The following nim code results in an error when compiling the generated C code:
The generated C code fails to compile when using Nim 2.0.0 or 2.0.2, Nim 1.6.16 results in no errors whatsoever.
Nim Version
Nim Compiler Version 2.0.0 [Linux: amd64] Compiled at 2023-08-01 Copyright (c) 2006-2023 by Andreas Rumpf
git hash: a488067a4130f029000be4550a0fb1b39e0e9e7c active boot switches: -d:release
Current Output
Expected Output
Possible Solution
Should this be a nim compile error? In the example, the type of
order
isseq[array[0..3, uint8]]
, however, the type ofOrder
isseq[array[ChannelId, uint8]]
, which I believe is what results in two instances of seq being generated in the C code.Additional Information
Declaring
order
as typeOrder
in the let statement does not result in any error.This might be an ARC/ORC issue: compiling with
--mm:arc
or--mm:orc
on 1.6.16 also results in the same error