struct Thing
{
int v;
};
interface IOp
{
This doOp();
};
extension Thing : IOp
{
This doOp()
{
Thing b = this;
b.v++;
return b;
}
};
extension int : IOp
{
This doOp()
{
// Might be confusing to C++ programmers.
// as 'this' isn't a pointer but the int *value*
return this + 1;
}
}
Doing
int a = ...;
a.doOp();
Produces multiple error messages of the form
.slang(42): error 30052: invalid swizzle pattern 'doOp' on type 'int'
Whereas
Thing thing = ...;
thing.doOp();
Works as expected.
Note a workaround that may be usable to sidestep this issue is to use a generic. For example
T doOp(T : IOp v) { return v.doOp(); }
// Works
doOp(a);
Take the following example
Doing
Produces multiple error messages of the form
Whereas
Works as expected.
Note a workaround that may be usable to sidestep this issue is to use a generic. For example