ios - 段错误 : 11 - Xcode/Swift 5 compile issue

标签 ios swift xcode

我总是收到 Segmentation fault: 11编译时出错。
我已经大量剥离了我的代码以识别导致问题的细微差别,并生成了下面的演示代码,该代码展示了完全相同的问题。
任何人都可以提出任何解决此问题的方法(这与我在代码注释中已经强调的不同)?
PS:这个 Swift 5 代码和 Xcode 11.7 和 Xcode 12 一起出现

// If we make this a class instead, it compiles! (but I want it to be a struct)
struct SomeStruct {
    // If we remove either of these properties or change them to an Int, it compiles! (but I obviously need 2 strings)
    let propertyA: String
    let propertyB: String
}

protocol Protocol { }

enum Enumeration {

    // If we remove this case, it compiles! (but I need this case, and the protocol also)
    case possibilityA(protocol: Protocol)

    // If we add additional associated values to this case, it compiles! (but I need this case)
    case possibilityB(completion: (Result<SomeStruct, Error>) -> ())
}

class SomeClass {

    func method() {
        // If we remove the use of `possibilityB`, it compiles! (but I need this)
        _ = Enumeration.possibilityB(completion: { _ in
        })
    }
}
这是堆栈转储...
Stack dump:
0.  Program arguments: /Applications/Xcode_12.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/x/Demo/Sources/Demo/Demo.swift -emit-module-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftmodule -emit-module-doc-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftdoc -emit-module-source-info-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftsourceinfo -serialize-diagnostics-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.dia -emit-dependencies-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.d -emit-reference-dependencies-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.swiftdeps -target arm64-apple-ios9.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk -I /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos -I /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -F /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos -F /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/x/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -Xcc -working-directory -Xcc /Users/x/Demo -enable-anonymous-context-mangled-names -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/swift-overrides.hmap -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos/include -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources-normal/arm64 -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources/arm64 -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -target-sdk-version 14.0 -parse-as-library -module-name Demo -o /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.o -embed-bitcode-marker -index-store-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Index/DataStore -index-system-modules 
1.  Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
2.  While evaluating request IRGenSourceFileRequest(IR Generation for file "/Users/x/Demo/Sources/Demo/Demo.swift")
3.  While emitting IR SIL function "@$s8Demo9SomeClassC6methodyyF".
 for 'method()' (at /Users/x/Demo/Sources/Demo/Demo.swift:21:5)
4.  While converting type '(@callee_guaranteed (@in_guaranteed Result<SomeStruct, Error>) -> ())'
0  swift                    0x0000000107a19865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000107a18865 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000107a19e1f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff68acc5fd _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000000004 _sigtramp + 18446603338760010276
5  swift                    0x00000001039794d8 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 21400
6  swift                    0x000000010396fc26 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8982
7  swift                    0x0000000103809dc7 swift::irgen::IRGenerator::emitGlobalTopLevel(llvm::StringSet<llvm::MallocAllocator>*) + 1607
8  swift                    0x00000001039449d7 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1687
9  swift                    0x000000010396d681 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 97
10 swift                    0x0000000103948dec llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 940
11 swift                    0x000000010394503d swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 269
12 swift                    0x0000000103590d3a performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3002
13 swift                    0x0000000103580928 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 20712
14 swift                    0x0000000103501c07 main + 1255
15 libdyld.dylib            0x00007fff688d3cc9 start + 1
16 libdyld.dylib            0x000000000000004f start + 18446603338762077063
error: Segmentation fault: 11 (in target 'Demo' from project 'Demo')

最佳答案

命名枚举关联值是一个阴影区域。虽然它在某些条件下显然被接受,但在官方的 Swift 语言指南枚举章节中没有使用甚至没有提到它。因此,在这种情况下,如果您删除命名,您的代码可以正常编译。

enum Enumeration {
    case possibilityA(Protocol)
    case possibilityB((Result<SomeStruct, Error>) -> ())
}
...
func method() {
    let _ = Enumeration.possibilityB({ _ in
})
在任何情况下,崩溃的编译器永远不会很好,无论你提供的代码有多糟糕,而且你得到了一个非常酷的最小测试,所以填写报告应该是你的职责和荣誉:)

关于ios - 段错误 : 11 - Xcode/Swift 5 compile issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63938592/

相关文章:

objective-c - 无法读取 Plist...我做错了什么?

javascript - 如何获得用户偏好的单位?米或英里

php - ASIHTTPRequest 将 json 发送到 php 服务器

ios - 在应用程序中随处显示弹出窗口,例如 UIAlertController

ios - 在Swift中自动调整多行UILabel的大小

iphone - 带标签的 Xcode 链接

iOS 7 - 使用 MKOverlayRenderer 在 MapKit 上绘制一组坐标

xcode - 我的 MainMenu.xib 拒绝进入 bundle ,并且我的应用程序崩溃并显示 : "Unable to load nib file: MainMenu, exiting"

ios - 如何从 Swift 3 中的父 View Controller 中删除 ChildViewController

ios - Swift 中的 NSTextStorage 子类不更新 UITextView