D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19840 - Ice in e2ir.d visit(CastExp) assert(false, "This case should have been rewritten to `__ArrayCast` in the semantic phase");
Summary: Ice in e2ir.d visit(CastExp) assert(false, "This case should have been rewrit...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P1 regression
Assignee: No Owner
URL:
Keywords: ice
Depends on:
Blocks:
 
Reported: 2019-05-01 13:16 UTC by Nicholas Wilson
Modified: 2019-05-02 07:26 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 Nicholas Wilson 2019-05-01 13:16:34 UTC
```
struct G
{
	ubyte[] I;
	alias I this; // Comment out to fix
}

auto M(ubyte[])
{
	G N;
	return N;
}
struct Tuple(fields...)
{
	fields expand;
}
alias P = Tuple!();

struct R { int T; }

struct U { R V; }

void X()
{
	import std.array;
	Appender!(U[])[P] Z;
	auto HB = P();
	Z[HB].put(cast(U[])[].M);
}
```

Introduced by https://github.com/dlang/dmd/pull/9516
Comment 1 Nicholas Wilson 2019-05-01 13:36:15 UTC
The extra R struct is not necessary in the above

The following crashes with a much deeper call stack (27 vs. 8):

struct G
{
	ubyte[] I;
	alias I this;
}

auto M(ubyte[])
{
	G N;
	return N;
}

struct U { int V; }

void X()
{
	func((cast(U[])[].M));
}

void func(U[]) {}
Comment 2 Mike Franklin 2019-05-02 00:12:22 UTC
The expression that is causing the problem is `cast(U[])M([]).I`

Unfortunately `I` is being reported as type `G` instead of type `ubyte[]` and that is why the compiler errors.

So I don't think PR 9516 has introduced any bug, but I do believe it has revealed a problem elsewhere in the compiler.  The solution will be to ensure `I` has a type of `ubyte[]` instead of G.
Comment 3 Mike Franklin 2019-05-02 00:59:04 UTC
Actually, scratch what I wrote above.  That was the result after I added some debugging code that incorrectly reported the type.

The problem appears to be that the `alias this` is not being resolved by the time the cast takes place.
Comment 4 Dlang Bot 2019-05-02 07:26:24 UTC
dlang/dmd pull request #9735 "Fix Issue 19840 - Ice in e2ir.d visit(CastExp)" was merged into stable:

- d07e3b88611a1f394bec7fd720cc6d8cac0d9daf by JinShil:
  Fix Issue 19840 - Ice in e2ir.d visit(CastExp)

https://github.com/dlang/dmd/pull/9735