You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Although we can't put try on the right side of ==, the right expression can contain a sub-expression that has try:
func nonThrowingFunc()->Int{0}func throwingFunc()throws->Int{0}func anotherNonThrowingFunc(_ integer:Int)->Int{ integer }print(nonThrowingFunc()==trythrowingFunc())// ❌ error: 'try' cannot appear to the right of a non-assignment operatorprint(nonThrowingFunc()==anotherNonThrowingFunc(trythrowingFunc()))// ✅ OK
However, #expect seems not to expect that there may be a try sub-expression on the right side of ==:
import Testing
structFoo:Equatable{init(){}init(_ integer:Int){}}@Testfunc myTest()throws{
#expect(try #require(Int("0"))==0)// ✅ OK
#expect((Foo()==Foo(try #require(Int("0"))))== true)// ✅ OK
#expect(Foo()==Foo(try #require(Int("0"))))// ❌ error: call can throw, but it is executed in a non-throwing autoclosure}
Expanded function named __checkBinaryOperation doesn't have an @autoclosure that throws.
Swift & OS version (output of swift --version ; uname -a)
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
Darwin yockow.local 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64
The text was updated successfully, but these errors were encountered:
… present.
For reasons that have been documented at length (see #162), we aren't able to
correctly expand conditions on `#expect()` or `#require()` that have effects
(`try` or `await`.) We aren't currently detecting all possible patterns that
expand incorrectly. This PR causes us to back out of the full expansion if the
`try` or `await` keyword is present _anywhere_ inside an expectation condition
expression.
Resolves#783.
Description
Although we can't put
try
on the right side of==
, the right expression can contain a sub-expression that hastry
:However,
#expect
seems not to expect that there may be atry
sub-expression on the right side of==
:Expanded function named
__checkBinaryOperation
doesn't have an@autoclosure
thatthrows
.Expected behavior
No error at compile time.
Actual behavior
Described above.
Steps to reproduce
Try to compile the code above.
swift-testing version/commit hash
Testing Library Version: 94 (arm64e-apple-macos13.0)
Swift & OS version (output of
swift --version ; uname -a
)swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
Darwin yockow.local 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64
The text was updated successfully, but these errors were encountered: