Bug 5094 – No implicit conversion with "alias property this"

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-21T10:05:00Z
Last change time
2010-12-06T00:20:04Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
rsinfu

Attachments

IDFilenameSummaryContent-TypeSize
789aliasthis-property.patchPatch against dmd r725, fixes implicitConvTo()text/plain1796

Comments

Comment #0 by rsinfu — 2010-10-21T10:05:37Z
Implicit conversion with help of alias this doesn't work if the aliased symbol is a property (or just nullary) function. The following code doesn't compile: -------------------- void main() { S s; int[] conv = s; // (4) } struct S { @property int[] get() { return [1,2,3]; } alias get this; } -------------------- % dmd -o- -c test.d test.d(4): Error: cannot implicitly convert expression (s) of type S to int[] -------------------- The repro code compiles fine if 'get' is a variable.
Comment #1 by rsinfu — 2010-10-21T10:07:27Z
Created attachment 789 Patch against dmd r725, fixes implicitConvTo() implicitConvTo() of TypeStruct and TypeClass don't deal with functions, and just tests convertion from function type to value type (then fails). The attached patch fixes the problem by adding a special check for functions. Passed dmd/druntime/phobos tests.
Comment #2 by bugzilla — 2010-12-06T00:20:04Z