From 21421395ba8210dd7679246310eafbb3e60f6347 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Fri, 13 Jun 2025 12:19:12 -0500 Subject: [PATCH] Add a test for property access on ~Escapable types This tests using a ~Escapable type as the LHS of a property access inside the `#expect` and `#require` macros. A ~Escapable return value from `#require` is unsupported. --- Tests/TestingTests/MiscellaneousTests.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Tests/TestingTests/MiscellaneousTests.swift b/Tests/TestingTests/MiscellaneousTests.swift index 6c3067984..92ac31b3c 100644 --- a/Tests/TestingTests/MiscellaneousTests.swift +++ b/Tests/TestingTests/MiscellaneousTests.swift @@ -595,3 +595,23 @@ struct MiscellaneousTests { #expect(duration < .seconds(1)) } } + +#if compiler(>=6.2) +extension Span { + var isNonEmpty: Bool { !isEmpty } + var nonZeroCount: Int? { isEmpty ? nil : count } +} + +extension MiscellaneousTests { + @available(macOS 26, iOS 26, watchOS 26, tvOS 26, visionOS 26, *) + @Test("Instance property of nonescapable type") + func propertyAccessOfNonescapable() throws { + let array = [1, 2, 3, 4, 5] + let span = array.span + #expect(!span.isEmpty) + #expect(span.isNonEmpty) + let count = try #require(span.nonZeroCount) + #expect(count == span.count) + } +} +#endif