Bug 13731 – Wrong interpretation of const keyword when creating @property returning class
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2014-11-13T22:41:00Z
Last change time
2014-11-13T22:57:12Z
Assigned to
nobody
Creator
buday48
Comments
Comment #0 by buday48 — 2014-11-13T22:41:37Z
class Foo
{
}
class Bar
{
Foo foo_;
Foo foo() const @property
{
return this.foo_; //<- Compilation Error
}
}
void main() {
}
DMD 2.066 gives an error message:
app.d(10): Error: cannot implicitly convert expression (this.foo_) of type const(Foo) to app.Foo
const keyword is actually used to specify function foo() but not its type Foo
Comment #1 by dmitry.olsh — 2014-11-13T22:51:39Z
Not a bug.
const is transitive which means that Bar is const inside of foo() and as such this.foo_ is also const.
http://dlang.org/const-faq.html