boschresearch / blech

Blech is a language for developing reactive, real-time critical embedded software.
Apache License 2.0
72 stars 5 forks source link

Exposing a constants requires to expose all constants in subexpression #63

Closed FriedrichGretz closed 3 years ago

FriedrichGretz commented 3 years ago

Describe the bug This code

module exposes C

const A: nat8 = 4
const B: nat8 = 18 
const C = A * (B - 2)

fails to compile with the error message that B (and A) is less accessible than C. However const expressions can be evaluated at compile time and so only the value 64 needs to be written to the signature not how it is calculated in the module.

Expected behaviour Above code should compile without errors.

Additional context Currently, const in Blech declares a compile time constant (aka #define) in C. If that changes due to complex types than the issue above might become more intricate.

schorg commented 3 years ago

This is not a bug - its a feature by design:

These considerations lead to the decision to make signature generation purely syntactic, not taking into account typing and constant evaluation.