Skip to content

[SR-5666] Swift 4 compiler crash in TypeChecker #48236

@hartbit

Description

@hartbit
Previous ID SR-5666
Radar rdar://problem/33296619
Original Reporter @hartbit
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.0 beta 5 (9M202q)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee @hartbit
Priority Medium

md5: 704fdc0cfe06a5574356fa09281fbb65

Issue Description:

In Xcode 9.0 beta 5 (9M202q), the following code crashes the compiler:

class C {
    var property: String?
}

func foo(cs: [C?]) -> [String?] {
    return cs.map({ c in
        let a = c.propertyWithTypo ?? "default"
        let b = "\(a)"
        return b
    })
} 

And here's the stack dump:

0  swift                    0x000000011002b7aa PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000011002abe6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fffaa948b3a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fca6896c388 _sigtramp + 3187816552
4  swift                    0x000000010db6b6d7 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 1079
5  swift                    0x000000010db6be14 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 388
6  swift                    0x000000010db6a51f swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 13359
7  swift                    0x000000010db68b1d swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 6701
8  swift                    0x000000010db67956 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 2150
9  swift                    0x000000010db6cef3 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 211
10 swift                    0x000000010da44290 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 5072
11 swift                    0x000000010dac7294 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 7764
12 swift                    0x000000010dac8968 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 13608
13 swift                    0x000000010dac48f2 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 1090
14 swift                    0x000000010daca2ab swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 475
15 swift                    0x000000010dae7d4a swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 2506
16 swift                    0x000000010d6188a7 swift::CompilerInstance::performSema() + 5031
17 swift                    0x000000010c9a46f8 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1384
18 swift                    0x000000010c9a2924 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7332
19 swift                    0x000000010c957f98 main + 12248
20 libdyld.dylib            0x00007fffaa739235 start + 1
21 libdyld.dylib            0x000000000000004f start + 1435266587
1.  While type-checking 'foo(cs:)' at /Users/david/Desktop/TestCrash/TestCrash/AppDelegate.swift:15:1
2.  While type-checking expression at [/Users/david/Desktop/TestCrash/TestCrash/AppDelegate.swift:16:12 - line:20:6] RangeText="cs.map({ c in
        let a = c.propertyWithTypo ?? "default"
        let b = "\(a)"
        return b
    })"

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwaretype checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions