D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9057 - Regression(Beta): Segfault or "Non-constant expression" error with local import
Summary: Regression(Beta): Segfault or "Non-constant expression" error with local import
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: ice, rejects-valid
Depends on:
Blocks:
 
Reported: 2012-11-22 14:20 UTC by bearophile_hugs
Modified: 2016-10-01 11:46 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 bearophile_hugs 2012-11-22 14:20:52 UTC
(This is derived from Issue 8996 )


import std.typecons;
Tuple!T foo(T)(T x) {
    return tuple(x);
}
void main() {
    import std.bigint;
    foo(BigInt(1));
}


DMD 2.061alpha gives:

...\dmd2\src\phobos\std\internal\math\biguintcore.d(92): Error: non-constant expression ZERO
Comment 1 Don 2012-11-28 00:42:42 UTC
Reduced test case shows it is related to the local import.
Looks as though semantic isn't being run on the array literal.
In the first case, it segfaults because the array literal type is still NULL.
------------------ 
struct Bug9057(T)
{
    T x;
}

void test9507() {
    import thug;
    Bug9057!(BugInt) xxx;
}
------------------ thug.d, case 1. Segfault
struct BugInt
{
    uint[] data = [0];
}
------------------ thug.d, case 2: "Non-constant expression ZEROX"
struct BugInt
{
    uint[] data = ZEROX;  
}
enum uint [] ZEROX = [0];
Comment 2 github-bugzilla 2012-12-10 03:56:00 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/af2c21b58e357a214da2bc1cf959c322f8ad1cd4
fix issue 9057 - Regression(Beta): Segfault or 'Non-constant expression' error with local import
Comment 3 github-bugzilla 2015-09-13 08:35:47 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/069f570005c1e571f23cd046b0e89503e2553f70
Add workaround for issue 9057, which is equivalent with the before

This is not a new workaround. In previous, the forward reference of struct instance fields had been resolved implicitly in  `sd->fields[i].getConstInitializer()`, via `sd->fill()`.
Comment 4 github-bugzilla 2016-04-26 04:54:47 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/f1e54366b7650665a820a27069d2f5a17ecae69b
Remove workaround for issue 9057

In https://github.com/dlang/dmd/pull/5500, issue 14666 has been properly fixed by adding mechanism of
deferred semantic2 running for imported modules. Now, the workaround for issue 9057 in `todt.c` is
unnecessary anymore.

https://github.com/dlang/dmd/commit/17aab68d6dfd8df39d50a8bd2851dafc820b3049
Merge pull request #5700 from 9rnsr/fix14666

Remove workaround for issue 9057
Comment 5 github-bugzilla 2016-10-01 11:46:27 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/f1e54366b7650665a820a27069d2f5a17ecae69b
Remove workaround for issue 9057

https://github.com/dlang/dmd/commit/17aab68d6dfd8df39d50a8bd2851dafc820b3049
Merge pull request #5700 from 9rnsr/fix14666