swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.34k forks source link

[SR-6048] Segmentation fault using KVO with generics in Swift 4 #48605

Open swift-ci opened 6 years ago

swift-ci commented 6 years ago
Previous ID SR-6048
Radar None
Original Reporter Sander (JIRA User)
Type Bug

Attachment: Download

Environment Xcode Version 9.0 (9A235) Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37) Target: x86_64-apple-macosx10.9
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash | |Assignee | None | |Priority | Medium | md5: fa0b7ccc243822c073f3f1c418197dd9

Issue Description:

I got segmentation fault using following code

class A<T>: NSObject {
    var aProperty: [T]?
}

class B<T, U: A<T>>: NSObject {
    var a: U?

    func function() {
        let observation = a?.observe(\.aProperty) { aValue, change in
        }
    }
}

belkadan commented 6 years ago
   Assertion failed: (t->is<ArchetypeType>() || t->isExistentialType() && "expected a class, archetype or existential"), function getSuperclassForDecl, file /Volumes/Data/swift-public/swift/lib/AST/Type.cpp, line 3230.

7  swift                    0x0000000109107504 swift::TypeBase::getSuperclassForDecl(swift::ClassDecl const*) + 308
8  swift                    0x000000010910762f swift::TypeBase::getContextSubstitutions(swift::DeclContext const*, swift::GenericEnvironment*) + 255
9  swift                    0x0000000109107ae0 swift::TypeBase::getMemberSubstitutions(swift::ValueDecl const*, swift::GenericEnvironment*) + 128
10 swift                    0x0000000109107c9b swift::TypeBase::getMemberSubstitutionMap(swift::ModuleDecl*, swift::ValueDecl const*, swift::GenericEnvironment*) + 75
11 swift                    0x0000000109107d50 swift::TypeBase::getTypeOfMember(swift::ModuleDecl*, swift::ValueDecl const*, swift::Type) + 80
12 swift                    0x000000010872065f (anonymous namespace)::RValueEmitter::visitKeyPathExpr(swift::KeyPathExpr*, swift::Lowering::SGFContext) + 783
13 swift                    0x0000000108717697 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 9783
14 swift                    0x0000000108710099 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57

1.  While emitting SIL for 'function()' at <stdin>:9:5
2.  While silgen emitFunction SIL function "@_T04main1BC8functionyyF".

cc @jckarter