Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6373] WritableKeyPath crash #48923

Closed
swift-ci opened this issue Nov 13, 2017 · 3 comments
Closed

[SR-6373] WritableKeyPath crash #48923

swift-ci opened this issue Nov 13, 2017 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software key paths Feature: key paths (both native and Objective-C)

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-6373
Radar None
Original Reporter yifei (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

OS X 10.13.1 (17B48)

Xcode 9.1 (9B55)

Swift 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, KeyPaths
Assignee None
Priority Medium

md5: 80128aea58efb4a2518d56d8de5fbabb

Issue Description:

The following code crashes the Swift 4.0.2 compiler during typechecking:

import Cocoa

struct InnerA {
    
}

struct InnerB {
    
}

enum Storage {
    case innerA(InnerA)
    case innerB(InnerB)
}

struct Outer {
    var storage: Storage?
    public var innerA: InnerA {
        get {
            if case .innerA(let v)? = storage { return v }
            return InnerA()
        }
        set { storage = .innerA(newValue) }
    }
    public var innerB: InnerB {
        get {
            if case .innerB(let v)? = storage { return v }
            return InnerB()
        }
        set { storage = .innerB(newValue) }
    }
    init() {
        storage = nil
    }
}

class Foo<InnerType> {
    let somePath: WritableKeyPath<Outer, InnerType>!
    init(_ path: WritableKeyPath<Outer, InnerType>, inner: InnerType) {
        self.somePath = path
        self.innerInstance = inner
        self.outerInstance = Outer()
    }
    
    var innerInstance: InnerType
    var outerInstance: Outer
    
    func update() {
        outerInstance[keyPath: somePath] = innerInstance
    }
}

Stacktrace:

0  swift                    0x0000000111fe658a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000111fe59c6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fff77e1bf5a _sigtramp + 26
3  swift                    0x000000010fb6a2c6 bool llvm::function_ref<bool (swift::Type, llvm::ArrayRef<swift::Requirement>)>::callback_fn<swift::GenericSignature::getSubstitutions(swift::SubstitutionMap const&, llvm::SmallVectorImpl<swift::Substitution>&) const::$_8>(long, swift::Type, llvm::ArrayRef<swift::Requirement>) + 150
4  swift                    0x000000010f8ef58f (anonymous namespace)::ExprRewriter::buildSubscript(swift::Expr*, swift::Expr*, llvm::ArrayRef<swift::Identifier>, bool, swift::constraints::ConstraintLocatorBuilder, bool, swift::AccessSemantics) + 1791
5  swift                    0x000000010f8de0bf swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 2799
6  swift                    0x000000010f8dd309 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 25
7  swift                    0x000000010fb21efa swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 11354
8  swift                    0x000000010f9faa11 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1537
9  swift                    0x000000010fa8042d swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 13869
10 swift                    0x000000010fa7c2b2 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 1090
11 swift                    0x000000010fa81c6b swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 475
12 swift                    0x000000010fa9f86a swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 2506
13 swift                    0x000000010f5c9427 swift::CompilerInstance::performSema() + 5031
14 swift                    0x000000010e93fcfb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1371
15 swift                    0x000000010e93df34 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
16 swift                    0x000000010e8f2bb8 main + 12248
17 libdyld.dylib            0x00007fff77b9b145 start + 1
18 libdyld.dylib            0x0000000000000044 start + 2286309120

Version: Xcode 9.1 (9B55), Swift 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)

@swift-ci
Copy link
Collaborator Author

Comment by Yifei Teng (JIRA)

My bad. Incorrectly labeled Swift 4.1. Should be Swift 4.0.2.

@belkadan
Copy link
Contributor

Fixed on master. @jckarter, do you have the dup?

@swift-ci
Copy link
Collaborator Author

Comment by Yifei Teng (JIRA)

Confirm fixed in latest Swift.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software key paths Feature: key paths (both native and Objective-C)
Projects
None yet
Development

No branches or pull requests

3 participants