mattgallagher / CwlPreconditionTesting

A Mach exception handler that allows Swift precondition failures to be caught and tested.
ISC License
175 stars 46 forks source link

Runtime crash occurs on Xcode 10 beta 1 #13

Closed ikesyo closed 6 years ago

ikesyo commented 6 years ago
Test Case '-[NimbleTests.ThrowAssertionTest testNegativeMessage]' started.
Fatal error: : file /Users/ikesyo/.ghq/github.com/Quick/Nimble/Tests/NimbleTests/Matchers/ThrowAssertionTest.swift, line 46
2018-06-06 17:27:05.902357-0700 xctest[79915:24107707] Fatal error: : file /Users/ikesyo/.ghq/github.com/Quick/Nimble/Tests/NimbleTests/Matchers/ThrowAssertionTest.swift, line 46
0    Nimble                             0x0000000103ef01c0 catchReturnTypeConverter<A>(_:block:) + 306
1    Nimble                             0x0000000103ef03b0 static NSException.catchException(in:) + 58
2    Nimble                             0x0000000103ec4ef0 closure #4 in catchBadInstruction(in:) + 172
3    Nimble                             0x0000000103ec5030 partial apply for closure #4 in catchBadInstruction(in:) + 35
4    Nimble                             0x0000000103ec5070 thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<MachContext>) -> (@error @owned Error) + 22
5    Nimble                             0x0000000103ec50f0 partial apply for thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<MachContext>) -> (@error @owned Error) + 27
6    libswiftCore.dylib                 0x0000000107337530 withUnsafePointer<A, B>(to:_:) + 12
7    libswiftCore.dylib                 0x00000001074f7ed0 withUnsafeMutablePointer<A, B>(to:_:) + 9
8    Nimble                             0x0000000103ec4170 catchBadInstruction(in:) + 954
9    Nimble                             0x0000000103ef04c0 closure #1 in throwAssertion() + 324
10   Nimble                             0x0000000103efed30 closure #1 in static Predicate.fromDeprecatedClosure(_:) + 120
11   Nimble                             0x0000000103effc60 partial apply for closure #1 in static Predicate.fromDeprecatedClosure(_:) + 38
12   Nimble                             0x0000000103efd8c0 Predicate.satisfies(_:) + 90
13   Nimble                             0x0000000103e7da40 run #1 <A>() in execute<A>(_:_:_:to:description:captureExceptions:) + 520
14   Nimble                             0x0000000103e7e640 closure #2 in execute<A>(_:_:_:to:description:captureExceptions:) + 152
15   Nimble                             0x0000000103e7e850 partial apply for closure #2 in execute<A>(_:_:_:to:description:captureExceptions:) + 83
16   Nimble                             0x0000000103e7e8b0 thunk for @escaping @callee_guaranteed () -> () + 45
17   Nimble                             0x0000000103e6c520 -[NMBExceptionCapture tryBlock:] + 56
18   Nimble                             0x0000000103e7d530 execute<A>(_:_:_:to:description:captureExceptions:) + 876
19   Nimble                             0x0000000103e7f290 Expectation.toNot(_:description:) + 300
20   NimbleTests                        0x0000000103c85420 closure #1 in ThrowAssertionTest.testNegativeMessage() + 358
21   Nimble                             0x0000000103ea1f70 closure #2 in withAssertionHandler(_:closure:) + 34
22   Nimble                             0x0000000103ea2010 partial apply for closure #2 in withAssertionHandler(_:closure:) + 17
23   Nimble                             0x0000000103e7e8b0 thunk for @escaping @callee_guaranteed () -> () + 45
24   Nimble                             0x0000000103e6c520 -[NMBExceptionCapture tryBlock:] + 56
25   Nimble                             0x0000000103ea1b60 withAssertionHandler(_:closure:) + 612
26   NimbleTests                        0x0000000103c1d020 failsWithErrorMessage(_:file:line:preferOriginalSourceLocation:closure:) + 376
27   NimbleTests                        0x0000000103c1eaf0 failsWithErrorMessage(_:file:line:preferOriginalSourceLocation:closure:) + 291
28   NimbleTests                        0x0000000103c85370 ThrowAssertionTest.testNegativeMessage() + 138
29   NimbleTests                        0x0000000103c85650 @objc ThrowAssertionTest.testNegativeMessage() + 36
30   CoreFoundation                     0x00007fff39778bb0 __invoking___ + 140
31   CoreFoundation                     0x00007fff397789d0 -[NSInvocation invoke] + 320
32   XCTest                             0x00000001003761c7 __24-[XCTestCase invokeTest]_block_invoke_2.195 + 65
33   XCTest                             0x00000001003e5008 -[XCTMemoryChecker _assertInvalidObjectsDeallocatedAfterScope:] + 51
34   XCTest                             0x000000010037f11a -[XCTestCase assertInvalidObjectsDeallocatedAfterScope:] + 116
35   XCTest                             0x00000001003760c8 __24-[XCTestCase invokeTest]_block_invoke.189 + 207
36   XCTest                             0x00000001003d4466 +[XCTestCase(Failures) performFailableBlock:shouldInterruptTest:] + 36
37   XCTest                             0x00000001003d439e -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 54
38   XCTest                             0x0000000100375a7c __24-[XCTestCase invokeTest]_block_invoke + 855
39   XCTest                             0x00000001003d931f -[XCUITestContext performInScope:] + 237
40   XCTest                             0x000000010037596c -[XCTestCase testContextPerformInScope:] + 87
41   XCTest                             0x00000001003759e6 -[XCTestCase invokeTest] + 137
42   XCTest                             0x0000000100377702 __26-[XCTestCase performTest:]_block_invoke_2 + 43
43   XCTest                             0x00000001003d4466 +[XCTestCase(Failures) performFailableBlock:shouldInterruptTest:] + 36
44   XCTest                             0x00000001003d439e -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 54
45   XCTest                             0x00000001003775ec __26-[XCTestCase performTest:]_block_invoke.334 + 88
46   XCTest                             0x00000001003e1050 +[XCTContext runInContextForTestCase:block:] + 225
47   XCTest                             0x0000000100376ab1 -[XCTestCase performTest:] + 675
48   XCTest                             0x00000001003bb616 -[XCTest runTest] + 57
49   XCTest                             0x0000000100371ba3 __27-[XCTestSuite performTest:]_block_invoke + 365
50   XCTest                             0x00000001003714af -[XCTestSuite _performProtectedSectionForTest:testSection:] + 55
51   XCTest                             0x0000000100371683 -[XCTestSuite performTest:] + 296
52   XCTest                             0x00000001003bb616 -[XCTest runTest] + 57
53   XCTest                             0x0000000100371ba3 __27-[XCTestSuite performTest:]_block_invoke + 365
54   XCTest                             0x00000001003714af -[XCTestSuite _performProtectedSectionForTest:testSection:] + 55
55   XCTest                             0x0000000100371683 -[XCTestSuite performTest:] + 296
56   XCTest                             0x00000001003bb616 -[XCTest runTest] + 57
57   XCTest                             0x0000000100371ba3 __27-[XCTestSuite performTest:]_block_invoke + 365
58   XCTest                             0x00000001003714af -[XCTestSuite _performProtectedSectionForTest:testSection:] + 55
59   XCTest                             0x0000000100371683 -[XCTestSuite performTest:] + 296
60   XCTest                             0x00000001003bb616 -[XCTest runTest] + 57
61   XCTest                             0x00000001003f5a98 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 171
62   XCTest                             0x00000001003f5c20 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.78 + 68
63   XCTest                             0x00000001003948f0 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 600
64   XCTest                             0x00000001003f5637 -[XCTTestRunSession runTestsAndReturnError:] + 639
65   XCTest                             0x0000000100357226 -[XCTestDriver runTestsAndReturnError:] + 424
66   XCTest                             0x00000001003dd6bd _XCTestMain + 1493
67   xctest                             0x00000001000022b8 main + 266
68   libdyld.dylib                      0x00007fff61a95014 start + 1
closure argument passed as @noescape to Objective-C has escaped: file /Users/ikesyo/.ghq/github.com/Quick/Nimble/Carthage/Checkouts/CwlCatchException/Sources/CwlCatchException/CwlCatchException.swift, line 28, column 36 
2018-06-06 17:27:06.180223-0700 xctest[79915:24107707] closure argument passed as @noescape to Objective-C has escaped: file /Users/ikesyo/.ghq/github.com/Quick/Nimble/Carthage/Checkouts/CwlCatchException/Sources/CwlCatchException/CwlCatchException.swift, line 28, column 36

This is rdar://40857699 which is originally found in https://github.com/Quick/Nimble/pull/530.

mattgallagher commented 6 years ago

That error is completely wrong. The block passed to Objective-C does not escape. It is called, not retained, and the function exits.

This looks like a bug in Swift 4.2's runtime checking. In any case, I'll have a look this evening and see if I can find a work-around.

mattgallagher commented 6 years ago

According to Swift developer Joe Groff, this is a confirmed Swift 4.2 bug.

https://twitter.com/jckarter/status/1004521338575261696

I'll still look for a workaround since I have no idea how long it will take this issue to be resolved in Xcode.

ikesyo commented 6 years ago

Yes, this is a Swift compiler bug (I and @phatblat are the reporters of this in the Swift lab).

Current workaround is https://github.com/Quick/Nimble/pull/537.

ikesyo commented 6 years ago

The fix for the compiler bug is somehow included in Xcode 10 beta 3 (https://github.com/Quick/Nimble/pull/560), so I'm closing this.