Bug 15478 – cases of missed CTFE evaluation when defining arrays dimensions

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-12-26T21:17:50Z
Last change time
2021-04-29T00:46:39Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
thomas.bockman

Comments

Comment #0 by thomas.bockman — 2015-12-26T21:17:50Z
struct Foo(N) { this(N value) { } auto bug() { return 0; } } void main() { enum Foo!int foo = 0; Foo!int[foo.bug] bar; // Error: integer constant expression expected instead of Foo().bug enum foo_bug = foo.bug; Foo!int[foo_bug] baz; // OK } The declarations of `baz` and `bar` should be semantically equivalent, but apparently something went wrong with `bar`. (This was reduced from a much larger program which triggered the problem seemingly at random. very annoying.)
Comment #1 by ag0aep6g — 2015-12-27T01:08:03Z
Looks like dmd doesn't realize that it's a function call between the brackets. Adding empty parentheses is a workaround. Here's a slightly smaller test case that shows a different error, but I suspect the same root cause: ---- int bug() { return 0; } void main() { int[bug()] bar1; /* works */ int[bug] bar2; /* Error: index is not a type or an expression */ } ----
Comment #2 by dlang-bot — 2019-06-25T22:03:25Z
@Basile-z created dlang/dmd pull request #10088 "fix issue 15478 - cases of missed CTFE evaluation when defining arrays dimensions" fixing this issue: - fix issue 15478 - cases of missed CTFE evaluation when defining arrays dimensions https://github.com/dlang/dmd/pull/10088
Comment #3 by dlang-bot — 2019-06-25T23:16:39Z
dlang/dmd pull request #10088 "fix issue 15478 - cases of missed CTFE evaluation when defining arrays dimensions" was merged into master: - f309b44f0e3a5fdd17e756a15dcba6926405bb5a by Basile Burg: fix issue 15478 - cases of missed CTFE evaluation when defining arrays dimensions https://github.com/dlang/dmd/pull/10088
Comment #4 by ag0aep6g — 2019-06-26T21:59:20Z
Reopening. The original test case still fails, but with a different error: ---- struct Foo(N) { this(N value) { } auto bug() { return 0; } } void main() { enum Foo!int foo = 0; Foo!int[foo.bug] bar; /* Error: need this for bug of type pure nothrow @nogc @safe int() */ enum foo_bug = foo.bug; Foo!int[foo_bug] baz; // OK } ----
Comment #5 by b2.temp — 2019-06-27T03:26:45Z
Open your eyes, the original test case is invalid. the function that gives the dim is not static so the error message is correct.
Comment #6 by b2.temp — 2019-06-27T03:28:02Z
Comment #7 by ag0aep6g — 2019-06-27T09:20:05Z
(In reply to Basile-z from comment #5) > Open your eyes, the original test case is invalid. the function that gives > the dim is not static so the error message is correct. The original test case is valid. There's no reason why the method should have to be static. Also, please refrain from snarky remarks like "open your eyes".
Comment #8 by b2.temp — 2019-06-27T14:16:32Z
Comment #9 by ag0aep6g — 2019-06-27T15:03:26Z
(In reply to Basile-z from comment #8) > https://www.youtube.com/watch?v=bLHL75H_VEM Title and content of that: "You're dereferencing a null pointer!" I realize that you're most likely just trying to insult me with that video. But if you think there would be a null dereference in the original test case, you're mistaken. `foo` is a valid instance of `Foo`. `foo.bug` is a valid call. Remember that the code works as expected when the call is written as `foo.bug()`. I'm reopening this again. If you close it again, please explain more elaborately and clearly how the original test case is invalid (preferably without external links). And please explain how it makes sense that it fails with `foo.bug` when it works with `foo.bug()`.
Comment #10 by b2.temp — 2019-06-28T09:25:37Z
No it was a kind of wink, you see, to reuse "open your eyes". This video is well known among the programmers so I thought you'd take this as a kind of de-dramatization of the situation.
Comment #11 by dlang-bot — 2021-04-28T13:37:49Z
@TungstenHeart updated dlang/dmd pull request #12481 "fix 21870 - Property/method not invoked and requires () when used in static array length" fixing this issue: - fix 21870, 15478 - Property/method not invoked and requires () when used in static array length https://github.com/dlang/dmd/pull/12481
Comment #12 by dlang-bot — 2021-04-29T00:46:39Z
dlang/dmd pull request #12481 "fix 21870 - Property/method not invoked and requires () when used in static array length" was merged into master: - 700a75c7179c1bc5fbbc89183961c3d8fd8e63a9 by Basile Burg: fix 21870, 15478 - Property/method not invoked and requires () when used in static array length https://github.com/dlang/dmd/pull/12481