Skip to content

Support property accesses on ~Escapable types #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

natecook1000
Copy link
Member

This adds support for having nonescapable types on the LHS of property accesses in the #expect(...) and #require(...) macros. This includes some additional changes that could lead to supporting a nonescapable result type in #require(...), but that may need more lifetime support in the language.

Motivation:

In the BinaryParsing library, I have a nonescapable ParserSpan type. In the tests, I need to write #expect(span.count == 0) instead of the more fluent #expect(span.isEmpty).

Modifications:

I've enabled lifetime annotations in the Testing and test targets, and then added overloads of __checkPropertyAccess and __checkValue that allow ~Escapable parameters.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This adds support for having nonescapable types on the LHS
of property accesses in the #expect(...) and #require(...) macros.
This includes some additional changes that could lead to supporting
a nonescapable result type in #require(...), but that may need
more lifetime support in the language.
@stmontgomery
Copy link
Contributor

Quick note up front that currently we expect our main branch to remain buildable using a 6.1 toolchain. (No further back than that, luckily.) So you may need #if compiler(>=6.2) guards in some places.

@grynspan
Copy link
Contributor

I asked Nate to look at branching from #840 instead of main here as the implementations are different and we wouldn't want to accidentally introduce something on main that was unsupportable under the new implementation.

@grynspan grynspan added enhancement New feature or request exit-tests ☠️ Work related to exit tests macros 🔭 Related to Swift macros such as @Test or #expect issue-handling Related to Issue handling within the testing library and removed exit-tests ☠️ Work related to exit tests labels Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request issue-handling Related to Issue handling within the testing library macros 🔭 Related to Swift macros such as @Test or #expect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants