The below code crashes DMD with the following message: Assertion failure: 'existing->op == TOKstructliteral' on line 2090 in file 'interpret.c' abnormal program termination //////////////////////////// import std.typecons; struct bar { static bar b = bar( 0 ); union { int[1] value; Tuple!( int ) fields; } this( int r ) { fields.expand[0] = r; } }
Reduced test case shows it doesn't require tuples. struct Fields4961 { int x; } struct bar4961 { union { int[1] value; Fields4961 fields; } this( int r ) { fields.x = r; } } static bar4961 b4961 = bar4961( 0 ); Interestingly, if you swap 'value' and 'fields', you get an error message with no line number: Error: duplicate union initialization for value
This example has been reduced to a limitation of CTFE. The original problem is gone. The below code works as expected: struct Fields4961 { int x; } struct bar4961 { union { int[1] value; Fields4961 fields; } this( int r ) { fields.x = r; } } static bar4961 b4961; // No longer initialized here. No CTFE problems. static this( ) { b4961 = bar4961( 0 ); }