Comment #0 by verylonglogin.reg — 2013-05-10T18:15:14Z
This module unittest fails when module is in a project but runs fine as a singe file so one have to look at the generated instructions to see the bug:
---
struct S
{
size_t[5] arr;
@property size_t opDollar() // line 5
{ return 0; }
int opIndex(size_t index)
{ return 0; }
}
interface I
{
final S getS()
{ return S(); }
}
class C: I
{
this(in size_t[])
{ }
}
unittest
{
auto i = cast(I) new C([0]);
i.getS()[$]; // Causes `null this` at line 5
}
---
Comment #1 by verylonglogin.reg — 2013-06-13T04:28:03Z
I was incorrect about the issue source. `opDollar` is just called on a garbage:
---
struct S
{
int x = 3;
@disable this();
this(int)
{ x = 7; }
int opSlice(size_t, size_t)
{ return 0; }
@property size_t opDollar()
{
assert(x == 7 || x == 3); // fails
assert(x == 7);
return 0;
}
}
void main()
{
auto x = S(0)[0 .. $];
}
---
As a result e.g. this will fail too:
---
import std.range;
void main()
{
auto x = zip([1])[$ - 1];
}
---