D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20589 - typeof may give wrong result in case of classes defining `opCall` operator
Summary: typeof may give wrong result in case of classes defining `opCall` operator
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-20 09:55 UTC by drug007
Modified: 2020-02-26 18:41 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description drug007 2020-02-20 09:55:48 UTC
```
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 drug007 2020-02-20 09:58:42 UTC
https://github.com/dlang/phobos/pull/7398
Comment 2 Dlang Bot 2020-02-20 13:44:13 UTC
@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 Dlang Bot 2020-02-26 18:41:16 UTC
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