Skip to content

Commit bc333b0

Browse files
committed
Fix __traits(getFunctionAttributes) example
The example code runner wraps the code in a function if no `main` is found, which makes the functions nested and changes attribute inference. Also the printed message is `tuple(...)` instead of `(...)`.
1 parent 4fd7517 commit bc333b0

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

spec/traits.dd

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,26 +735,41 @@ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
735735
---
736736
int sum(int x, int y) pure nothrow { return x + y; }
737737

738-
// prints ("pure", "nothrow", "@system")
739738
pragma(msg, __traits(getFunctionAttributes, sum));
740739

741740
struct S
742741
{
743742
void test() const @system { }
744743
}
745744

746-
// prints ("const", "@system")
747745
pragma(msg, __traits(getFunctionAttributes, S.test));
746+
747+
void main(){}
748748
---
749+
)
750+
751+
Prints:
752+
753+
$(CONSOLE
754+
tuple("pure", "nothrow", "@system")
755+
tuple("const", "@system")
749756
)
750757

751758
$(P Note that some attributes can be inferred. For example:)
752759

753760
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
754761
---
755-
// prints ("pure", "nothrow", "@nogc", "@trusted")
756762
pragma(msg, __traits(getFunctionAttributes, (int x) @trusted { return x * 2; }));
763+
764+
void main(){}
757765
---
766+
)
767+
768+
Prints:
769+
770+
$(CONSOLE
771+
tuple("pure", "nothrow", "@nogc", "@trusted")
772+
)
758773
)
759774
)
760775

0 commit comments

Comments
 (0)