GCC 4.7 and older successfully compiles this:
union S {
int a;
float b;
};
int main() {
const S s = {.b = 1.0};
}
Run
@Araq Why should we enforce const in C? It must be enforced in Nim, not the
backend, non?
@mratsim I gave it a try but the root problem is that C++ compilers do not
support "named fields in const unions" (yet?), a C99 addition. So you can only
initialize the first field of a union and nothing else.
Can't we do the other way around, start supporting case objects properly across
compile-time to runtime boundary?
That would be very useful for both
[nimbus](https://github.com/status-im/nimbus/blob/78714295dab4ead5e56c0048c46ae07d8bbed91a/nimbus/vm/interpreter/gas_costs.nim#L360-L361),
as a co
Fair enough, consider it done.
Then why don't you start the deprecation process?
Actually you cannot use `case object` in `const` sections. The compiler can't
enforce this currently because it would break existing code where it happens to
work.
Yes,
There are a couple of issues with variants set at compile-time and then used at
runtime:
*
[https://github.com/nim-lang/Nim/issues/11862](https://github.com/nim-lang/Nim/issues/11862)
*
[https://github.com/nim-lang/Nim/issues/8015](https://github.com/nim-lang/Nim/issues/8015)
*
[ht
In the following code assertion is failed. Looks like a bug. Should I create an
issue?
import macros
type
Kind = enum kind1, kind2
Foo = object
case kind: Kind
of kind1: val1: int
of kind2: val2: int
macro test(node: untype