D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7751 - [ICE] (Regression 2.059head) From auto and forward reference
Summary: [ICE] (Regression 2.059head) From auto and forward reference
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: ice, pull
: 7778 (view as issue list)
Depends on:
Blocks:
 
Reported: 2012-03-22 05:17 UTC by bearophile_hugs
Modified: 2012-03-29 15:20 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-03-22 05:17:25 UTC
This is wrong D2 code because Foo has no constructor:


class Foo(T) {
    T x;
    Foo y;
}
auto foo(T)(T x, Foo!T y=null) {
    return new Foo!T(x, y);
}
void bar(U)(U foo, U[] spam=[]) {
    spam ~= [];
}
void main() {
    bar(foo(0));
}



DMD 2.059head gives:

test.d(6): Error: no constructor for Foo
test.d(12): Error: template instance test.foo!(int) error instantiating

Followed by a crash.



If I remove the template of Foo:


class Foo {
    int x;
    Foo y;
}
auto foo(int x, Foo y=null) {
    return new Foo(x, y);
}
void bar(U)(U foo, U[] spam=[]) {
    spam ~= [];
}
void main() {
    bar(foo(0));
}



DMD gives this and no crash:

test.d(6): Error: no constructor for Foo
test.d(12): Error: forward reference to foo
Comment 2 Kenji Hara 2012-03-25 18:16:09 UTC
From issue 7778:
> This code snippet crashes DMD 2.059head:
> ---
> auto foo(){bar[]r;r~=[];}
> ---
> It does not crash DMD 2.058

The same reason crashes above code.
Comment 3 Kenji Hara 2012-03-25 18:16:58 UTC
*** Issue 7778 has been marked as a duplicate of this issue. ***
Comment 4 github-bugzilla 2012-03-29 12:12:47 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/cd7d2fc3843ffa96d6c8413ba1dbc5b90c7b05de
Merge pull request #828 from 9rnsr/fix7751

Issue 7751 - [ICE] From auto and forward reference
Comment 5 github-bugzilla 2012-03-29 15:20:15 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/a4d1e283f85e4258e31e05e31fcc948199b69239
Merge pull request #848 from donc/regression7751

Fix issue 7751, improve error handling