D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4961 - ICE(interpret.c) Tuple in union as part of static struct member
Summary: ICE(interpret.c) Tuple in union as part of static struct member
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2010-09-30 12:52 UTC by Simen Kjaeraas
Modified: 2011-09-16 08:57 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Simen Kjaeraas 2010-09-30 12:52:16 UTC
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;
    }
}
Comment 1 Don 2010-10-05 01:56:06 UTC
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
Comment 2 Simen Kjaeraas 2011-09-16 08:57:00 UTC
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 );
}