Bug 14166 – [REG2.066] Excess CTFE running for the temporary variable in module level expression

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-10T15:00:00Z
Last change time
2015-02-21T09:11:25Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
vlevenfeld

Comments

Comment #0 by vlevenfeld — 2015-02-10T15:00:21Z
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. */
Comment #1 by k.hara.pg — 2015-02-10T15:19:29Z
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.
Comment #2 by dlang-bugzilla — 2015-02-10T15:28:23Z
(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
Comment #3 by k.hara.pg — 2015-02-10T15:44:59Z
(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.
Comment #4 by k.hara.pg — 2015-02-11T03:38:17Z
Comment #5 by github-bugzilla — 2015-02-11T04:34:37Z
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
Comment #6 by github-bugzilla — 2015-02-21T09:11:25Z
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