How to workaround this SourceKitService crash?

I want to implement a simple method which makes use of another method from the same generic type Observable<T>, but there is a weird issue which lets Swift 4.2 crash. Since I kind of really need this method to work, I ask for a suggestion how to workaround the issue to stop the compiler from crashing but achieving the same API.

This extension always crashes the compiler or some part of it. The observable type comes from RxSwift library.

extension Observable {
  ///
  struct Expectation : OptionSet {
    let rawValue: UInt8

    static var noNext: Expectation {
      return Expectation(rawValue: 1 << 0)
    }

    static var noError: Expectation {
      return Expectation(rawValue: 1 << 1)
    }

    static var noCompletion: Expectation {
      return Expectation(rawValue: 1 << 2)
    }

    static var noDispose: Expectation {
      return Expectation(rawValue: 1 << 3)
    }
  }

  ///
  func assert(
    _ expectation: Expectation,
    message: @escaping @autoclosure () -> String = "",
    file: StaticString = #file,
    line: UInt = #line
  ) -> Observable {
    //
    func _assert(_ value: Expectation) {
      if expectation.contains(value) {
        assertionFailure(message, file: file, line: line)
      }
    }
    //
    return self.do(
      onNext: { _ in _assert(.noNext) },
      onError: { _ in _assert(.noError) },
      onCompleted: { _assert(.noCompletion) },
      onSubscribe: nil,
      onSubscribed: nil,
      onDispose: { _assert(.noDispose) }
    )
  }
}

Here are the crash logs:

Process:               SourceKitService [2556]
Path:                  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/XPCServices/SourceKitService.xpc/Contents/MacOS/SourceKitService
Identifier:            SourceKitService
Version:               1.0 (1000.11.42)
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           com.apple.dt.SKAgent [919]
User ID:               501

Date/Time:             2018-12-11 09:32:33.461 +0100
OS Version:            Mac OS X 10.14.2 (18C54)
Report Version:        12
Anonymous UUID:        B5B50505-AA2C-1A48-0019-265101F733F0


Time Awake Since Boot: 7400 seconds

System Integrity Protection: enabled

Crashed Thread:        3

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000008
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [2556]

VM Regions Near 0x8:
--> 
    __TEXT                 0000000102305000-0000000104ca4000 [ 41.6M] r-x/rwx SM=COW  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/XPCServices/SourceKitService.xpc/Contents/MacOS/SourceKitService

Application Specific Information:
dyld2 mode

Thread 0:: Dispatch queue: com.apple.root.default-qos.overcommit
0   libsystem_kernel.dylib        	0x00007fff64ccf0a2 __sigsuspend_nocancel + 10
1   libdispatch.dylib             	0x00007fff64b538b5 _dispatch_sigsuspend + 21
2   libdispatch.dylib             	0x00007fff64b538a0 _dispatch_sig_thread + 53

Thread 1:
0   libsystem_pthread.dylib       	0x00007fff64d843f8 start_wqthread + 0
1   ???                           	0x0000000000000a03 0 + 2563

Thread 2:: Dispatch queue: sourcekit.swift.ASTBuilding
0   libsystem_kernel.dylib        	0x00007fff64ccd94e __ulock_wait + 10
1   libsystem_pthread.dylib       	0x00007fff64d8970a _pthread_join + 356
2   com.apple.SourceKitService.1000.11.42_osx	0x00000001049b9cfd executeOnLargeStackThread(void*) + 93
3   libdispatch.dylib             	0x00007fff64b43dcf _dispatch_client_callout + 8
4   libdispatch.dylib             	0x00007fff64b4a124 _dispatch_lane_serial_drain + 618
5   libdispatch.dylib             	0x00007fff64b4abdc _dispatch_lane_invoke + 388
6   libdispatch.dylib             	0x00007fff64b53090 _dispatch_workloop_worker_thread + 603
7   libsystem_pthread.dylib       	0x00007fff64d8460b _pthread_wqthread + 409
8   libsystem_pthread.dylib       	0x00007fff64d84405 start_wqthread + 13

Thread 3 Crashed:
0   com.apple.SourceKitService.1000.11.42_osx	0x00000001029fd661 (anonymous namespace)::SILTypeSubstituter::visitType(swift::CanType) + 241
1   com.apple.SourceKitService.1000.11.42_osx	0x00000001029fd803 (anonymous namespace)::SILTypeSubstituter::substSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>) + 387
2   com.apple.SourceKitService.1000.11.42_osx	0x00000001029fdec3 swift::SILFunctionType::substGenericArgs(swift::SILModule&, llvm::ArrayRef<swift::Substitution>) + 275
3   com.apple.SourceKitService.1000.11.42_osx	0x00000001025b89d4 (anonymous namespace)::Callee::getTypeInfo(swift::Lowering::SILGenFunction&, bool) const & + 644
4   com.apple.SourceKitService.1000.11.42_osx	0x00000001025c47e5 swift::Lowering::SILGenFunction::emitApplyOfLibraryIntrinsic(swift::SILLocation, swift::FuncDecl*, llvm::ArrayRef<swift::Substitution> const&, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::SGFContext) + 629
5   com.apple.SourceKitService.1000.11.42_osx	0x00000001025c4532 swift::Lowering::SILGenFunction::emitApplyOfLibraryIntrinsic(swift::SILLocation, swift::FuncDecl*, swift::SubstitutionMap const&, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::SGFContext) + 226
6   com.apple.SourceKitService.1000.11.42_osx	0x00000001025f3b33 swift::Lowering::SILGenFunction::emitPointerToPointer(swift::SILLocation, swift::Lowering::ManagedValue, swift::CanType, swift::CanType, swift::Lowering::SGFContext) + 867
7   com.apple.SourceKitService.1000.11.42_osx	0x000000010260dff1 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 22817
8   com.apple.SourceKitService.1000.11.42_osx	0x000000010267ddcb swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 491
9   com.apple.SourceKitService.1000.11.42_osx	0x00000001026378d4 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 772
10  com.apple.SourceKitService.1000.11.42_osx	0x00000001025a520d swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 237
11  com.apple.SourceKitService.1000.11.42_osx	0x0000000102618238 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 40
12  com.apple.SourceKitService.1000.11.42_osx	0x00000001025bcacd (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 5293
13  com.apple.SourceKitService.1000.11.42_osx	0x00000001025bd5b2 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 898
14  com.apple.SourceKitService.1000.11.42_osx	0x00000001025bb6fb (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 219
15  com.apple.SourceKitService.1000.11.42_osx	0x00000001025b9b42 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 482
16  com.apple.SourceKitService.1000.11.42_osx	0x00000001025b81dd (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1693
17  com.apple.SourceKitService.1000.11.42_osx	0x00000001025b57dd (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3037
18  com.apple.SourceKitService.1000.11.42_osx	0x00000001025b1fa9 swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 1513
19  com.apple.SourceKitService.1000.11.42_osx	0x000000010261ffc3 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 819
20  com.apple.SourceKitService.1000.11.42_osx	0x000000010267a943 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6547
21  com.apple.SourceKitService.1000.11.42_osx	0x000000010267c4e3 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 13619
22  com.apple.SourceKitService.1000.11.42_osx	0x000000010267a8e7 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6455
23  com.apple.SourceKitService.1000.11.42_osx	0x0000000102636dde swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 462
24  com.apple.SourceKitService.1000.11.42_osx	0x00000001025a24d4 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 516
25  com.apple.SourceKitService.1000.11.42_osx	0x00000001025a1802 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 1042
26  com.apple.SourceKitService.1000.11.42_osx	0x000000010267a98b swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6619
27  com.apple.SourceKitService.1000.11.42_osx	0x0000000102636dde swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 462
28  com.apple.SourceKitService.1000.11.42_osx	0x00000001025a24d4 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 516
29  com.apple.SourceKitService.1000.11.42_osx	0x00000001025a1802 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 1042
30  com.apple.SourceKitService.1000.11.42_osx	0x00000001025ac334 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 276
31  com.apple.SourceKitService.1000.11.42_osx	0x00000001025ab25b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 971
32  com.apple.SourceKitService.1000.11.42_osx	0x00000001025ad0fe swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 1310
33  com.apple.SourceKitService.1000.11.42_osx	0x0000000102343282 void SourceKit::WorkQueue::DispatchData::callAndDelete<(anonymous namespace)::ASTProducer::getASTUnitAsync(SourceKit::SwiftASTManager::Implementation&, llvm::ArrayRef<llvm::IntrusiveRefCntPtr<SourceKit::ImmutableTextSnapshot> >, std::__1::function<void (llvm::IntrusiveRefCntPtr<SourceKit::ASTUnit>, llvm::StringRef)>)::$_3>(void*) + 10674
34  libdispatch.dylib             	0x00007fff64b43dcf _dispatch_client_callout + 8
35  libdispatch.dylib             	0x00007fff64b46b6c _dispatch_block_invoke_direct + 260
36  com.apple.SourceKitService.1000.11.42_osx	0x00000001049b9d1f executeBlock(void*) + 15
37  com.apple.SourceKitService.1000.11.42_osx	0x000000010243d6bd ExecuteOnThread_Dispatch(void*) + 13
38  libsystem_pthread.dylib       	0x00007fff64d85305 _pthread_body + 126
39  libsystem_pthread.dylib       	0x00007fff64d8826f _pthread_start + 70
40  libsystem_pthread.dylib       	0x00007fff64d84415 thread_start + 13

Thread 3 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x00007fd8c5b04100  rcx: 0x00007fd8c7b438f8  rdx: 0x00007fd8c5b04100
  rdi: 0x0000000000000600  rsi: 0x0000000000000200  rbp: 0x00007000098b37a0  rsp: 0x00007000098b3700
   r8: 0x0000000000000007   r9: 0x00007fd8c7b438f8  r10: 0x00007fd8c5b04100  r11: 0x00007fd8c7b43b78
  r12: 0x00007000098b3750  r13: 0x0000000000000008  r14: 0x00007000098b3980  r15: 0x00007fd8c7b43b78
  rip: 0x00000001029fd661  rfl: 0x0000000000010206  cr2: 0x0000000000000008
  
Logical CPU:     2
Error Code:      0x00000004
Trap Number:     14


Binary Images:
       0x102305000 -        0x104ca3ff3  com.apple.SourceKitService.1000.11.42_osx (1.0 - 1000.11.42) <C77BBCF5-1622-392B-BF6B-D11E0F5A51DD> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/sourcekitd.framework/Versions/A/XPCServices/SourceKitService.xpc/Contents/MacOS/SourceKitService
       0x109378000 -        0x1093f6a67  dyld (640.2) <289AB27E-F09F-3384-A14A-100431139559> /usr/lib/dyld
    0x7fff62006000 -     0x7fff62007ffb  libSystem.B.dylib (1252.200.5) <25F4A1F5-6551-312F-B397-C8D45ACC530A> /usr/lib/libSystem.B.dylib
    0x7fff62260000 -     0x7fff622b7ff7  libc++.1.dylib (400.9.4) <B260AC33-EB9A-30C6-8746-D011B3B02B08> /usr/lib/libc++.1.dylib
    0x7fff622b8000 -     0x7fff622cdfff  libc++abi.dylib (400.17) <446F4748-8A89-3D2E-AE1C-27EEBE93A8AB> /usr/lib/libc++abi.dylib
    0x7fff634f1000 -     0x7fff63521ff7  libncurses.5.4.dylib (53.200.3) <2B715386-F391-3835-909F-A6DD86DCB4E3> /usr/lib/libncurses.5.4.dylib
    0x7fff63aad000 -     0x7fff64233fe7  libobjc.A.dylib (750.1) <804715F4-F52D-34D0-8FEC-A25DC08513C3> /usr/lib/libobjc.A.dylib
    0x7fff64990000 -     0x7fff649a2ffb  libz.1.dylib (70.200.4) <15F7B40A-424C-33BB-BF2C-7E8195128B78> /usr/lib/libz.1.dylib
    0x7fff64a13000 -     0x7fff64a17ff3  libcache.dylib (81) <704331AC-E43D-343A-8C24-39201142AF27> /usr/lib/system/libcache.dylib
    0x7fff64a18000 -     0x7fff64a22ff3  libcommonCrypto.dylib (60118.220.1) <9C865644-EE9A-3662-AB77-7C8A5E561784> /usr/lib/system/libcommonCrypto.dylib
    0x7fff64a23000 -     0x7fff64a2afff  libcompiler_rt.dylib (63.4) <817772E3-E836-3FFD-A39B-BDCD1C357221> /usr/lib/system/libcompiler_rt.dylib
    0x7fff64a2b000 -     0x7fff64a34ff3  libcopyfile.dylib (146.200.3) <5C5C4F35-DAB7-3CF1-940F-F47192AB8289> /usr/lib/system/libcopyfile.dylib
    0x7fff64a35000 -     0x7fff64ab9fdf  libcorecrypto.dylib (602.230.1) <C78D1A87-5543-3561-BEB4-3B480BA94ECB> /usr/lib/system/libcorecrypto.dylib
    0x7fff64b40000 -     0x7fff64b7aff7  libdispatch.dylib (1008.220.2) <2FDB1401-5119-3DF0-91F5-F4E105F00CD7> /usr/lib/system/libdispatch.dylib
    0x7fff64b7b000 -     0x7fff64baaff3  libdyld.dylib (640.2) <376E3F3A-6942-3B0E-AD5E-4B97E8255CF5> /usr/lib/system/libdyld.dylib
    0x7fff64bab000 -     0x7fff64babffb  libkeymgr.dylib (30) <A4EFD9A4-2EF3-3E18-B325-F527E3821939> /usr/lib/system/libkeymgr.dylib
    0x7fff64bb9000 -     0x7fff64bb9ff7  liblaunch.dylib (1336.220.5) <8563299C-2493-3DBD-8E88-3FC673DB47DD> /usr/lib/system/liblaunch.dylib
    0x7fff64bba000 -     0x7fff64bbffff  libmacho.dylib (921) <6ADB99F3-D142-3A0A-B3CE-031354766ACC> /usr/lib/system/libmacho.dylib
    0x7fff64bc0000 -     0x7fff64bc2ffb  libquarantine.dylib (86.220.1) <58524FD7-63C5-38E0-9D90-845A79551C14> /usr/lib/system/libquarantine.dylib
    0x7fff64bc3000 -     0x7fff64bc4ff3  libremovefile.dylib (45.200.2) <BA53CA8A-9974-3A43-9265-B110B1AE470F> /usr/lib/system/libremovefile.dylib
    0x7fff64bc5000 -     0x7fff64bdcff3  libsystem_asl.dylib (356.200.4) <33C62769-1242-3BC1-9459-13CBCDECC7FE> /usr/lib/system/libsystem_asl.dylib
    0x7fff64bdd000 -     0x7fff64bddfff  libsystem_blocks.dylib (73) <152EDADF-7D94-35F2-89B7-E66DCD945BBA> /usr/lib/system/libsystem_blocks.dylib
    0x7fff64bde000 -     0x7fff64c66fff  libsystem_c.dylib (1272.200.26) <D6C701A2-9F17-308D-B6AC-9E17EF31B7DF> /usr/lib/system/libsystem_c.dylib
    0x7fff64c67000 -     0x7fff64c6aff7  libsystem_configuration.dylib (963.200.27) <94898525-ECC8-3CC9-B312-CBEAAC305E32> /usr/lib/system/libsystem_configuration.dylib
    0x7fff64c6b000 -     0x7fff64c6eff7  libsystem_coreservices.dylib (66) <10818C17-70E1-328E-A3E3-C3EB81AEC590> /usr/lib/system/libsystem_coreservices.dylib
    0x7fff64c6f000 -     0x7fff64c75ffb  libsystem_darwin.dylib (1272.200.26) <07468CF7-982F-37C4-83D0-D5E602A683AA> /usr/lib/system/libsystem_darwin.dylib
    0x7fff64c76000 -     0x7fff64c7cff7  libsystem_dnssd.dylib (878.230.2) <FF9D5025-F060-334B-B6D8-C5D0BB6A55E3> /usr/lib/system/libsystem_dnssd.dylib
    0x7fff64c7d000 -     0x7fff64cc9ff3  libsystem_info.dylib (517.200.9) <54B65F21-2E93-3579-9B72-6637A03245D9> /usr/lib/system/libsystem_info.dylib
    0x7fff64cca000 -     0x7fff64cf2ff7  libsystem_kernel.dylib (4903.231.4) <ABDAABCA-C22A-3960-AA4E-E91A9FF34929> /usr/lib/system/libsystem_kernel.dylib
    0x7fff64cf3000 -     0x7fff64d3eff7  libsystem_m.dylib (3158.200.7) <AF25F8E8-194C-314F-A2D3-A424853EE796> /usr/lib/system/libsystem_m.dylib
    0x7fff64d3f000 -     0x7fff64d63ff7  libsystem_malloc.dylib (166.220.1) <4777DC06-F9C6-356E-82AB-86A1C6D62F3A> /usr/lib/system/libsystem_malloc.dylib
    0x7fff64d64000 -     0x7fff64d6fff3  libsystem_networkextension.dylib (767.220.1) <74818C3D-9B68-3823-A737-6A4B782618F2> /usr/lib/system/libsystem_networkextension.dylib
    0x7fff64d70000 -     0x7fff64d77fff  libsystem_notify.dylib (172.200.21) <65B3061D-41D7-3485-B217-A861E05AD50B> /usr/lib/system/libsystem_notify.dylib
    0x7fff64d78000 -     0x7fff64d81fef  libsystem_platform.dylib (177.200.16) <83DED753-51EC-3B8C-A98D-883A5184086B> /usr/lib/system/libsystem_platform.dylib
    0x7fff64d82000 -     0x7fff64d8cfff  libsystem_pthread.dylib (330.230.1) <BA382BFC-6A17-3940-B417-D090EF2AF4F4> /usr/lib/system/libsystem_pthread.dylib
    0x7fff64d8d000 -     0x7fff64d90ff7  libsystem_sandbox.dylib (851.230.3) <4D0CB1CA-160C-3C29-BE5D-131D68D43B1B> /usr/lib/system/libsystem_sandbox.dylib
    0x7fff64d91000 -     0x7fff64d93ff3  libsystem_secinit.dylib (30.220.1) <5964B6D2-19D4-3CF9-BDBC-4EB1D42348F1> /usr/lib/system/libsystem_secinit.dylib
    0x7fff64d94000 -     0x7fff64d9bff7  libsystem_symptoms.dylib (820.237.2) <487E1794-4C6E-3B1B-9C55-95B1A5FF9B90> /usr/lib/system/libsystem_symptoms.dylib
    0x7fff64d9c000 -     0x7fff64db1ff7  libsystem_trace.dylib (906.220.1) <4D4BA88A-FA32-379D-8860-33838723B35F> /usr/lib/system/libsystem_trace.dylib
    0x7fff64db3000 -     0x7fff64db8ffb  libunwind.dylib (35.4) <EF1A77FD-A86B-39F5-ABEA-6100AB23583A> /usr/lib/system/libunwind.dylib
    0x7fff64db9000 -     0x7fff64de9fff  libxpc.dylib (1336.220.5) <DC50F33E-C47D-3256-BFE0-F8E9B5AEBE17> /usr/lib/system/libxpc.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 4431
    thread_create: 0
    thread_set_state: 214

VM Region Summary:
ReadOnly portion of Libraries: Total=274.8M resident=0K(0%) swapped_out_or_unallocated=274.8M(100%)
Writable regions: Total=125.1M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=125.1M(100%)
 
                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Activity Tracing                   256K        2 
Dispatch continuations            16.0M        2 
Kernel Alloc Once                    8K        2 
MALLOC                            99.0M       27 
MALLOC guard page                   16K        5 
STACK GUARD                         16K        5 
Stack                             9768K        6 
Stack Guard                       64.0M        3 
VM_ALLOCATE (reserved)             256K        2         reserved VM address space (unallocated)
__DATA                            3624K       43 
__LINKEDIT                       221.2M        4 
__TEXT                            53.6M       42 
mapped file                       70.4M       58 
shared memory                       12K        4 
===========                     =======  ======= 
TOTAL                            537.8M      191 
TOTAL, minus reserved VM space   537.6M      191 

I'll file a bug report later today.

Okay I found the issue myself. :radioactive: And it's something that I have reported in the past. :sweat: The compiler crashed because I attempted to 'forward' an escaping autoclosure to another function that takes an escaping autoclosure. Calling explicitly the function message() fixed the crash.

@Slava_Pestov literately yesterday you marked this issue as resolved. Did you meant it's resolved for Swift 5 or also in Swift 4.2? This thread proves it isn't fixed in Swift 4.2.

  ///
  func assert(
    _ expectation: Expectation,
    message: @escaping @autoclosure () -> String = "",
    file: StaticString = #file,
    line: UInt = #line
  ) -> Observable<E> {
    //
    func _assert(_ value: Expectation) {
      Swift.assert(
        expectation.contains(value) == false,
        // use `()` to fix a crash: https://bugs.swift.org/browse/SR-5718
        message(), 
        file: file,
        line: line
      )
    }
    //
    return self.do(
      onNext: { _ in _assert(.noNext) },
      onError: { _ in _assert(.noError) },
      onCompleted: { _assert(.noCompletion) },
      onSubscribe: nil,
      onSubscribed: nil,
      onDispose: { _assert(.noDispose) }
    )
  }

It's resolved in swift-5.0-branch and master only, and not in any released version.

1 Like