D safety! New Feature?
Chris Wright via Digitalmars-d
digitalmars-d at puremagic.com
Sat Aug 6 07:46:12 PDT 2016
On Sat, 06 Aug 2016 07:56:29 +0200, ag0aep6g wrote:
> On 08/06/2016 03:38 AM, Chris Wright wrote:
>> Some reflection stuff is a bit inconvenient:
>>
>> class A {
>> int foo() { return 1; }
>> }
>>
>> void main() {
>> auto a = new immutable(A);
>> // This passes:
>> static assert(is(typeof(a.foo)));
>> // This doesn't:
>> static assert(__traits(compiles, () { a.foo; }));
>> }
>>
>> __traits(compiles) is mostly an evil hack, but things like this require
>> its use.
>
> The two are not equivalent, though. The first one checks the type of the
> method.
Which is a bit awkward because in no other context is it possible to
mention a raw method. You invoke it or you get a delegate to it.
And if you try to get a delegate explicitly to avoid this, you run into
https://issues.dlang.org/show_bug.cgi?id=1983 .
It's also a bit awkward for a method to be reported to exist with no way
to call it. While you can do the same with private methods, you get a
warning:
a.d(7): Deprecation: b.B.priv is not visible from module a
Which implies that this will become illegal at some point and fail to
compile.
More information about the Digitalmars-d
mailing list