digitalmars.D.learn - isCallable is not an expression
- andre (67/67) Sep 24 2014 Hi,
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (22/24) Sep 24 2014 Submitted the following bug report:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (21/27) Sep 24 2014 1) You need a "this template parameter":
- andre (3/3) Sep 25 2014 Thanks a lot.
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();
}
Sep 24 2014
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
Sep 24 2014
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
Sep 24 2014









=?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> 