Bug 10511 – Unhelpful error messages with a const opDispatch
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-06-30T07:52:37Z
Last change time
2018-01-08T13:45:32Z
Keywords
diagnostic
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-06-30T07:52:37Z
Modified from code by David in D.learn. This is wrong code:
struct Foo {
static Foo opDispatch(string s)() const {
return Foo();
}
}
void main() {
Foo f = Foo.bar();
}
DMD 2.064alpha gives:
test.d(7): Error: no property 'bar' for type 'Foo'
test.d(7): Error: Foo is not an expression
The error messages don't help much because they don't explain what's the problem. The code able to compile is without "const":
struct Foo {
static Foo opDispatch(string s)() {
return Foo();
}
}
void main() {
Foo f = Foo.bar();
}
Comment #1 by public — 2013-06-30T08:26:33Z
Why static const methods are allowed in the very first place? Is there a legit use case?
Comment #2 by bearophile_hugs — 2013-06-30T08:56:06Z
(In reply to comment #1)
> Why static const methods are allowed in the very first place? Is there a legit
> use case?
I think it's a regression (maybe already reported in Bugzillza), because this code:
const void foo() {}
void main() {}
Used to give:
Error: function test.foo without 'this' cannot be const/immutable
Comment #3 by bearophile_hugs — 2013-06-30T08:58:03Z
(In reply to comment #2)
> I think it's a regression (maybe already reported in Bugzillza),
It's Issue 10482
Comment #4 by razvan.nitu1305 — 2018-01-08T13:45:32Z
The code from the original bug report fails compiling with:
test.d(2): Error: function is10511.Foo.opDispatch!"bar".opDispatch without this cannot be const
test.d(7): Error: template instance is10511.Foo.opDispatch!"bar" error instantiating
Which the correct error message.
Closing as fixed.