Skip to content

Comments

Add more traits doc examples & make existing examples runnable#2507

Merged
dlang-bot merged 4 commits intodlang:masterfrom
n8sh:traits-doc-examples
Nov 18, 2018
Merged

Add more traits doc examples & make existing examples runnable#2507
dlang-bot merged 4 commits intodlang:masterfrom
n8sh:traits-doc-examples

Conversation

@n8sh
Copy link
Member

@n8sh n8sh commented Nov 9, 2018

The motivation for the new examples is to demonstrate:

  • Pointers are considered scalar but not arithmetic or integral.
  • __vectors have the same traits as their element type.
  • enums have the same traits as the underlying type.

Also made most of the existing code examples runnable while I was at it.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @n8sh!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@n8sh n8sh force-pushed the traits-doc-examples branch from e64ecf9 to 845eebd Compare November 9, 2018 01:47
@thewilsonator
Copy link
Contributor

LGTM, but whats with DAutoTest? Looks like some of those examples are not compilable?

@n8sh n8sh force-pushed the traits-doc-examples branch 3 times, most recently from 84d3065 to b9df4a2 Compare November 10, 2018 00:06
spec/traits.dd Outdated
$(P This array can be used by a precise GC to avoid false pointers.)
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---
class C
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets a void main wrapped around it, thus making it nested adding an extra pointer to it, throwing off the size calculations. Easiest to just remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SPEC_RUNNABLE_EXAMPLE_COMPILE that is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No please don't remove it. Better fix the script or you know use static

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding static at what appears to be the top level would be confusing. I think maybe the best thing is to wrap this with a fake main and include static.

@n8sh n8sh force-pushed the traits-doc-examples branch 3 times, most recently from 676da01 to e060844 Compare November 13, 2018 23:53
writeln(__traits(getMember, s, "m" ~ "x")); // 1

__traits(getMember, S, "mx") = 1; // error, no this for S.mx
// __traits(getMember, S, "mx") = 1; // error, no this for S.mx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a __traits(compiles)?

@@ -985,6 +1127,7 @@ void main()
test();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    alias tests = Tuple!(__traits(getUnitTests, foo));
    static assert(tests.length == 1);

Why is this failing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's because the example isn't compiled with -unittest.

@n8sh
Copy link
Member Author

n8sh commented Nov 17, 2018

Added a commit that changes example code to be compiled with -unittest.

@thewilsonator
Copy link
Contributor

@n8sh

Searching for tabs
./changelog/pending.dd:240:	"vibe-d": "~>X.Y.Z"
posix.mak:822: recipe for target 'test' failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants