Attempting to set a value to a struct property which is referenced by an UnsafePointer causes Xcode to fail with Abort trap: 6

Originator:alin.claudiu.radut
Number:rdar://21699570 Date Originated:2015/07/07
Status:Duplicate of 21559246 (Open) Resolved:
Product:Xcode Product Version:7.0 beta (7A121l)
Classification: Reproducible:Always
 
Summary:
Having defined a C struct in BridgingHeader.h with the following structure:
struct info_type {
    int priority;
};

And then attempting to modify the memory pointed by an unsafe pointer like this:
class ViewController: UIViewController {
    func viewDidLoad() {
        var info = info_type()
        info.priority = 2    
        processInfo(&info)
    }

    func processInfo(infoRef: UnsafePointer<info_type>) {
        info.memory.priority = 1
    }
}

will cause the Xcode parser to fail.

Steps to Reproduce:
1. Create a new Swift project
2. Add a bridging header file
3. Add the following code to the bridging header:
struct info_type {
    int priority;
};
4. Replace the ViewController class with the following:
class ViewController: UIViewController {
    override func viewDidLoad() {
        var info = info_type()
        info.priority = 2    
        processInfo(&info)
    }

    func processInfo(infoRef: UnsafePointer<info_type>) {
        info.memory.priority = 1
    }
}

Expected Results:
Xcode should notify the user that the memory for the struct pointed by infoRef cannot be modified because it's an UnsafePointer and that an UnsafeMutablePointer should be used.

Actual Results:
Xcode shows a problem (red exclamation mark) in the issues tab and stops parsing the code in the project. The problem is the following:

Assertion failed: (GetSetInfo.getInt().hasValue()), function getSetterAccessibility, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.42.3/src/swift/include/swift/AST/Decl.h, line 4070.
0  swift                    0x0000000110340b9b llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x00000001103412db SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff8eaacf1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff518bbbec _sigtramp + 3269520620
4  libsystem_c.dylib        0x00007fff8ef73b53 abort + 129
5  libsystem_c.dylib        0x00007fff8ef3bc39 basename + 0
6  swift                    0x000000010eafb1a0 void filterForDiscriminator<swift::ValueDecl*>(llvm::SmallVectorImpl<swift::ValueDecl*>&, swift::DebuggerClient*) + 0
7  swift                    0x000000010e950e0c diagnoseSubElementFailure(swift::Expr*, swift::SourceLoc, swift::constraints::ConstraintSystem&, swift::Diag<llvm::StringRef>, swift::Diag<swift::Type>) + 668
8  swift                    0x000000010e9b6908 swift::constraints::ConstraintSystem::computeAssignDestType(swift::Expr*, swift::SourceLoc) + 968
9  swift                    0x000000010e95ab65 swift::ASTVisitor<(anonymous namespace)::ConstraintGenerator, swift::Type, void, void, void, void, void>::visit(swift::Expr*) + 9317
10 swift                    0x000000010e95d58b (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*) + 75
11 swift                    0x000000010ea72f1c swift::Expr::walk(swift::ASTWalker&) + 76
12 swift                    0x000000010e958219 swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 201
13 swift                    0x000000010e9afdbb swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, bool, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&) + 203
14 swift                    0x000000010e9b56f3 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, bool, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*) + 243
15 swift                    0x000000010ea16cbb swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 491
16 swift                    0x000000010ea15fd9 (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 25
17 swift                    0x000000010ea1509f swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 415
18 swift                    0x000000010ea14eb1 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 49
[...]

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!