In the following code, I expect the pragma to output "int". When static if (1) causes a null dereference in CTFE. Manually lowering (static if (0)) causes the code to behave as expected. ///// struct Proxy (T) { T* ptr; ref deref () { return *ptr; } alias deref this; } struct Test { auto opIndex () { return this; } auto opIndex (int) { return 1; } } template Elem (R) { static if (0) // 0 => Elem == int; 1 => Error: dereference of null pointer 'this.ptr' alias Elem = typeof(R.init[][0]); else alias Elem = typeof(R.init[].opIndex (0)); } void main () { alias T = Proxy!Test; pragma (msg, Elem!T); } /* dmd git-HEAD outputs this: source/app.d(11): Error: dereference of null pointer 'this.ptr' source/app.d(31): called from here: Proxy(null).deref() source/app.d(37): Error: template instance app.Elem!(Proxy!(Test)) error instantiating source/app.d(37): while evaluating pragma(msg, Elem!(Proxy!(Test))) FAIL .dub/build/application-debug-linux.posix-x86_64-dmd_2067-905D3FE7D130796D902AA401E263BCF6/ testing executable Error executing command run: dmd failed with exit code 1. */
Is this really a regression? With 2.066.1 and, 2.066, same error happens. And with 2.065, the error is changed to: test.d(28): Error: Test cannot be sliced with [] test.d(36): Error: template instance test.Elem!(Proxy!(Test)) error instantiating test.d(36): while evaluating pragma(msg, Elem!(Proxy!(Test))) because multidimensional indexing/slicing operator overload is not yet supported.
(In reply to Kenji Hara from comment #1) > Is this really a regression? With 2.066.1 and, 2.066, same error happens. > > And with 2.065, the error is changed to: Sorry about that. This code compiles in 2.065 but not 2.066: ////////////// test.d ///////////// struct Proxy (T) { T* ptr; ref deref () { return *ptr; } alias deref this; } struct Test { auto opIndex () { return this; } auto opIndex (int) { return 1; } } template Elem (R) { alias Elem = typeof(R.init[0]); } void main () { alias T = Proxy!Test; pragma (msg, Elem!T); } /////////////////////////////////// Introduced in https://github.com/D-Programming-Language/dmd/pull/3569
(In reply to Vladimir Panteleev from comment #2) > (In reply to Kenji Hara from comment #1) > > Is this really a regression? With 2.066.1 and, 2.066, same error happens. > > > > And with 2.065, the error is changed to: > > Sorry about that. This code compiles in 2.065 but not 2.066: > [snip] Thanks. I found that the root of the first rejects-valid case is same with the second regression case. But I want a little more time for the think of the good way to fix the issue.
https://github.com/D-Programming-Language/dmd/pull/4403
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/44a3c6377eb1a2ebc914b497b360c1459b9f1dad fix Issue 14166 - Excess CTFE running for the temporary variable in module level expression https://github.com/D-Programming-Language/dmd/commit/202871ccbcbe4fca09de4aaac99b7f808050a003 Merge pull request #4403 from 9rnsr/fix14166 [REG2.066] Issue 14166 - Excess CTFE running for the temporary variable in module level expression
Commits pushed to https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/44a3c6377eb1a2ebc914b497b360c1459b9f1dad fix Issue 14166 - Excess CTFE running for the temporary variable in module level expression https://github.com/D-Programming-Language/dmd/commit/202871ccbcbe4fca09de4aaac99b7f808050a003 Merge pull request #4403 from 9rnsr/fix14166