Bug 20589 – typeof may give wrong result in case of classes defining `opCall` operator

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-02-20T09:55:48Z
Last change time
2020-02-26T18:41:16Z
Assigned to
No Owner
Creator
drug007

Comments

Comment #0 by drug2004 — 2020-02-20T09:55:48Z
``` import std; class AClass { T opCall(T)(T p) { return p; } } void main(){ Array!AClass arr; } ``` compiles with error ``` ... phobos/std/conv.d(4434): Error: need this for opCall of type pure nothrow @nogc @safe AClass(AClass p) ``` The reason is that in std.conv.emplaceRef ``` static if (is(typeof(chunk = T(args)))) chunk = T(args); ``` `is(typeof(chunk = T(args)))` return true but the expression `chunk = T(args);` do not compiles nevertheless.
Comment #1 by drug2004 — 2020-02-20T09:58:42Z
Comment #2 by dlang-bot — 2020-02-20T13:44:13Z
@drug007 updated dlang/phobos pull request #7398 "Fix issue 20589 - typeof may give wrong result in case of classes defining `opCall` operator" mentioning this issue: - Test for issue 20589 https://github.com/dlang/phobos/pull/7398
Comment #3 by dlang-bot — 2020-02-26T18:41:16Z
dlang/phobos pull request #7398 "Fix issue 20589 - typeof may give wrong result in case of classes defining `opCall` operator" was merged into master: - 7ffdfef3f75d521cc7b0b2659e438f501f263ca1 by drug007: Fix issue 20589 - typeof may give wrong result in case of classes defining `opCall` operator - e4959d4777be74a426aa6d8c58abc5308a62b92b by drug007: Test for issue 20589 https://github.com/dlang/phobos/pull/7398