Bug 2813 – implicit cast (implemented via alias this) is not triggered when returning from function

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-04-06T15:19:00Z
Last change time
2015-06-09T01:18:02Z
Keywords
rejects-valid
Assigned to
nobody
Creator
2korden

Comments

Comment #0 by 2korden — 2009-04-06T15:19:04Z
struct Proxy { private Object o; Object get() { return o; } alias get this; } class Bar { Object getObject() { //return _proxy; // should work, but doesn't Object o = _proxy; return o; // works but not like intended } private Proxy _proxy; } test.d(14): Error: cannot implicitly convert expression (this._proxy) of type Proxy to object.Object
Comment #1 by andrej.mitrovich — 2011-05-24T22:26:46Z
Works in 2.053: struct Proxy { private Object o; Object get() { return o; } alias get this; } class Bar { Object getObject() { return _proxy; // should work, but doesn't } private Proxy _proxy; } void main() { auto bar = new Bar(); auto proxy = bar.getObject(); assert(proxy is null); }