@@ -3676,6 +3676,27 @@ function: 'test.main', pretty function: 'int test.main(string[] args)',
3676
3676
file full path: '/example/test.d'
3677
3677
)
3678
3678
3679
+ $(PANEL $(P $(RED Warning): Do not use $(D mixin(__FUNCTION__)) to get the
3680
+ symbol for the current function. This seems to be a common
3681
+ thing for programmers to attempt when trying to get the symbol
3682
+ for the current function in order to do introspection on it,
3683
+ since D does not currently have a direct way to get that
3684
+ symbol. However, using $(D mixin(__FUNCTION__)) means that the
3685
+ symbol for the function will be looked up by name, which means
3686
+ that it's subject to the various rules that go with symbol
3687
+ lookup, which can cause various problems. One such problem
3688
+ would that if a function is overloaded, the result will be the
3689
+ first overload whether that's the current function or not.)
3690
+
3691
+ $(P Given that D doesn't currently have a way to directly get the
3692
+ symbol for the current function, the best way to do it is to
3693
+ get the parent symbol of a symbol within the function, since
3694
+ that avoids any issues surrounding symbol lookup rules. An
3695
+ example of that which doesn't rely on any other symbols is
3696
+ $(D __traits(parent {})). It declares an anonymous, nested
3697
+ function, whose parent is then the current function. So,
3698
+ getting its parent gets the symbol for the current function.))
3699
+
3679
3700
$(H2 $(LNAME2 associativity, Associativity and Commutativity))
3680
3701
3681
3702
$(P An implementation may rearrange the evaluation of expressions
0 commit comments