August 08, 2020 [Issue 21137] New: Can't get the UDA given to the lambda expression parameters | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21137 Issue ID: 21137 Summary: Can't get the UDA given to the lambda expression parameters Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: zan77137@nifty.com A UDA given to non-typed parameters in lambda expression/function literal cannot be detected: ------------------------ import std; template detectUDA(alias f) { // Can't give the lambda to the Parameters. // It does not satisfy isCallable pragma(msg, __traits(getAttributes, Parameters!f[0..1])[0]); void detectUDA() {} } void main() { detectUDA!((@(1) int a) => a); // OK detectUDA!((@(1) a) => a); // Error detectUDA!(delegate(@(2) int a) {}); // OK detectUDA!(delegate(@(2) a) {}); // Error detectUDA!((@(3) int a) {}); // OK detectUDA!((@(3) a) {}); // Error } ------------------------ This example deals with Parameters, which, as far as I know, will not be taken out in any way. In addition, there are few ways to get traits of a non-typed lambda expression other than whether it can be called using arguments of certain types. New __traits may be needed to solve the problem. -- |
Copyright © 1999-2021 by the D Language Foundation