Skip to content

Params initialized with params leads to an error in generated code #13

@schorg

Description

@schorg

If you try to initialize a param with another param the type-checker does not complain.
But, the generated code cannot be compiled by a C-compiler

To Reproduce
The following program in file typing.blc

param x: int32 = 42

param y: int32 = x * 2

@[EntryPoint]
activity Test() returns int32
    await true
    return y
end

compiles without errors

blechc --app  typing.blc

A C compiler cannot compile the generated code

cd blech
clang -Iinclude blech.c

and shows the following error message

In file included from blech.c:21:
./typing.c:42:54: error: initializer element is not a compile-time constant
static blc_int32 blc_01typing01_y = blc_01typing01_x * 2;
                                    ~~~~~~~~~~~~~~~~~^~~
1 error generated.

Expected behaviour
Either a typing error in the Blech compiler,
Or even better - but much more effort and a big change - a different code generation for parameter initialization, maybe as a function, called from the initialiser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions