| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
September 24, 2014 isCallable is not an expression | ||||
|---|---|---|---|---|
| ||||
Hi, following code throws an error when I uncomment method getPropertyDuplicate. getPropertyDuplicate is just a copy of getProperty except the method name. Why these errors are thrown? C:\D\dmd2\windows\bin\..\..\src\phobos\std\traits.d(1257): Error: isCallable!(ge tPropertyDuplicate) is not an expression source\app.d(25): while looking for match for functionAttributes!(getProp ertyDuplicate) C:\D\dmd2\windows\bin\..\..\src\phobos\std\traits.d(1257): Error: template insta nce std.traits.isCallable!(getPropertyDuplicate) error instantiating source\app.d(11): instantiated from here: functionAttributes!(getProperty Duplicate) source\app.d(11): while looking for match for functionAttributes!(getProp ertyDuplicate) Kind regards André template MyTemplate() { import std.traits : isSomeFunction, functionAttributes, FunctionAttribute, ReturnType; string[] getPropertyNames() { string[] result; foreach(m;__traits(allMembers, typeof(this))) { static if (isSomeFunction!(__traits(getMember, typeof(this), m)) && functionAttributes!(__traits(getMember, typeof(this), m)) & FunctionAttribute.property) { result ~= m; } } return result; } /*string[] getPropertyDuplicate() { string[] result; foreach(m;__traits(allMembers, typeof(this))) { static if (isSomeFunction!(__traits(getMember, typeof(this), m)) && functionAttributes!(__traits(getMember, typeof(this), m)) & FunctionAttribute.property) { result ~= m; } } return result; }*/ } class A { mixin MyTemplate; } void main() { auto a = new A(); } | ||||
September 24, 2014 Re: isCallable is not an expression | ||||
|---|---|---|---|---|
| ||||
Posted in reply to andre | On 09/24/2014 01:11 AM, andre wrote: > static if (isSomeFunction!(__traits(getMember, > typeof(this), m)) Submitted the following bug report: https://issues.dlang.org/show_bug.cgi?id=13528 import std.traits; mixin template MyTemplate() { void foo() { pragma(msg, __traits(getMember, typeof(this), "foo")); } } class A { mixin MyTemplate; } void main() { auto a = new A(); } Error: Internal Compiler Error: CTFE DotType: this.A while evaluating pragma(msg, __traits(getMember, A, "foo")) Ali | |||
September 24, 2014 Re: isCallable is not an expression | ||||
|---|---|---|---|---|
| ||||
Posted in reply to andre | On 09/24/2014 01:11 AM, andre wrote:
> template MyTemplate()
> {
> import std.traits : isSomeFunction, functionAttributes,
> FunctionAttribute, ReturnType;
>
> string[] getPropertyNames()
1) You need a "this template parameter":
string[] getPropertyNames(this MyType)()
2) Now, replace all typeof(this) expressions with MyType below.
> /*string[] getPropertyDuplicate()
3) Same here:
string[] getPropertyDuplicate(this MyType)()
And it works! :)
class A {
mixin MyTemplate;
@property int zzz()
{
return 42;
}
}
void main() {
auto a = new A();
import std.string;
assert(a.getPropertyNames() == [ "zzz" ]);
assert(a.getPropertyDuplicate() == [ "zzz" ]);
}
Ali
| |||
September 25, 2014 Re: isCallable is not an expression | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | Thanks a lot. Kind regards André | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply