ldc-developers/ldc — Issue #34: StructType::setBody assert isOpaque() failed
Author: Trass3r
Created: 2011-12-05 03:34:07+00:00
State: open

```d
//matrix.d:
import vector;
struct Matrix
{
vec4 v;
}

//vector.d:
template Tuple(T...)
{
alias T Tuple;
}

template Repeat(T, int count)
{
static if (!count)
alias Tuple!() Repeat;
else
alias Tuple!(T, Repeat!(T, count-1)) Repeat;
}

struct Vector(T, int dim)
{
Repeat!(T, dim) tuple;

const static Vector zero = Vector();
@property T length()
{

float res;

return res;
}

Vector opOpAssign(string op, U:Vector)(U v)
{
foreach (i, _; tuple)
mixin("tuple[i] " ~ op ~ "= v.tuple[i];");

return this;
}
T distance(Vector other)	{
other -= this;
return other.length;
}
}

alias Vector!(float, 4) vec4;
```

```
$ ldc2 -c *.d
ldc2: llvm-3.0/lib/VMCore/Type.cpp:401: void llvm::StructType::setBody(llvm::ArrayRef, bool): Assertion `isOpaque() && "Struct body already set!"' failed.
```

Pulling the vector code into the matrix module makes it compile.