Comment #0 by denis.gladkiy — 2015-02-08T09:44:27Z
Created attachment 1475
The to crash DMD.
The compiler (2.066.1) crashes when compiling this:
pure auto mul(const int[] left, const int[] right)
{
return zip(left, right).map!(a => a[0] * a[1]) ;
}
pure auto mul(const int[] left, const int[] right)
{
return zip(left, right).map!(a => a[0] * a[1]) ;
}
Assertion failure: 'type->ty != Tstruct || ((TypeStruct *)type)->sym == this' on line 912 in file 'struct.c'
I've attached the code to reproduce the bug.
Comment #1 by ketmar — 2015-02-08T10:28:38Z
seems that this assert() is right, and the code in `StructDeclaration::semantic()` is missing one check.
here we have a check for the same condition:
if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this)
{
TemplateInstance *ti = ((TypeStruct *)type)->sym->isInstantiated();
if (ti && isError(ti))
((TypeStruct *)type)->sym = this;
}
seems that second `if` is missing `else` part with `error()`.
Comment #2 by k.hara.pg — 2015-02-08T13:34:35Z
Reduced test case:
struct S(alias func) { void foo() { func(1); } }
void main()
{
}
pure auto mul(const int[] left, const int[] right)
{
S!(a => a)().foo();
}
pure auto mul(const int[] left, const int[] right)
{
S!(a => a)().foo();
}
In the two identical functions, the S!(a => a) will create different instances, but their mangled names are wrongly identical. Then It makes the internal compiler error (assertion failure).
Comment #4 by github-bugzilla — 2018-01-24T11:39:20Z
Commit pushed to master at https://github.com/dlang/dmdhttps://github.com/dlang/dmd/commit/ab47b8b0cf18d14c1ffbc97df6c8fb299971170a
Issue 14147 - Compiler crash on identical functions in a single module (#7577)
* fix Issue 2789 - Functions overloads are not checked for conflicts
* Allow an overload declaration hack, which is actually used in druntime
If two extern (C) functions are just declared with different signatures,
they don't conflict.
extern(C):
alias sigfn_t = void function(int);
alias sigfn_t2 = void function(int) nothrow @nogc;
sigfn_t bsd_signal(int sig, sigfn_t func);
sigfn_t2 bsd_signal(int sig, sigfn_t2 func) nothrow @nogc; // no error
This behavior must be reconsidered in the future.
* fix Issue 14147 - Compiler crash on identical functions in a single module
* Allow an overload declaration hack, which is actually used in druntime
* Fix the testsuite
* PR 4396 Fixup
* Remove duplicate definition in the DMD backend