Swift 2.0b5: swiftc crash typechecking malformed enum initialization

Originator:rix.rob
Number:rdar://22202420 Date Originated:08-Aug-2015 10:13 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A176x)
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
I got myself into an interesting state where a crasher occurs when typechecking a malformed program.


Steps to Reproduce:
1. This (malformed) program:
struct S {
	init(_ : E) {}
}

enum E {
	init() {
		let
		self = .C(S(.A))
	}

	case A
	case C(S)
}


Expected Results:
should not crash swiftc


Actual Results:
but totally does:
rob@Resonance ~/Desktop> swiftc boom.swift; and ./boom
boom.swift:8:3: error: keyword 'self' cannot be used as an identifier
                self = .C(S(.A))
                ^
Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.52.2/src/llvm/include/llvm/Support/Casting.h, line 95.
0  swift                    0x000000010f801bbb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x000000010f8022fb SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff9644deaa _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff00000000 _sigtramp + 1773871472
4  libsystem_c.dylib        0x00007fff985183fb abort + 129
5  libsystem_c.dylib        0x00007fff984dfa44 basename + 0
6  swift                    0x000000010ddffbd1 (anonymous namespace)::FailureDiagnosis::typeCheckArbitrarySubExprIndependently(swift::Expr*, bool) + 353
7  swift                    0x000000010ddfe988 (anonymous namespace)::FailureDiagnosis::diagnoseGeneralFailure() + 328
8  swift                    0x000000010ddfb9c5 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 10533
9  swift                    0x000000010ddf628b swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 923
10 swift                    0x000000010ddf76e7 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*, bool) + 4343
11 swift                    0x000000010de5db30 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 784
12 swift                    0x000000010de63502 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 450
13 swift                    0x000000010ddfda00 (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, bool) + 384
14 swift                    0x000000010ddf6202 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 786
15 swift                    0x000000010ddf76e7 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*, bool) + 4343
16 swift                    0x000000010de5db30 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 784
17 swift                    0x000000010de63502 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 450
18 swift                    0x000000010de64223 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*) + 99
19 swift                    0x000000010de643c4 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int) + 244
20 swift                    0x000000010de8018b validatePatternBindingDecl(swift::TypeChecker&, swift::PatternBindingDecl*, unsigned int) + 875
21 swift                    0x000000010de7c95e (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 558
22 swift                    0x000000010de7c718 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 152
23 swift                    0x000000010dec73d4 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 420
24 swift                    0x000000010dec6789 (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 25
25 swift                    0x000000010dec5cef swift::TypeChecker::typeCheckConstructorBodyUntil(swift::ConstructorDecl*, swift::SourceLoc) + 879
26 swift                    0x000000010dec5655 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 37
27 swift                    0x000000010dec638a swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 138
28 swift                    0x000000010de4b67c typeCheckFunctionsAndExternalDecls(swift::TypeChecker&) + 220
29 swift                    0x000000010de4c4a9 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int) + 1913
30 swift                    0x000000010dc52c28 swift::CompilerInstance::performSema() + 4152
31 swift                    0x000000010d7c250c performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 748
32 swift                    0x000000010d7c1fc8 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2728
33 swift                    0x000000010d7be02f main + 2015
34 libdyld.dylib            0x00007fff94b775ad start + 1
Stack dump:
0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file boom.swift -target x86_64-apple-darwin15.0.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -color-diagnostics -module-name boom -o /var/folders/9y/f7n4rvx901nctm_5d16c1wm40000gn/T/boom-9dfc39.o 
1.	While type-checking 'init' at boom.swift:6:2
2.	While type-checking declaration 0x7ffec3006348 at boom.swift:7:3
3.	While type-checking expression at [boom.swift:8:10 - line:8:18] RangeText=".C(S(.A))"
4.	While type-checking expression at [boom.swift:8:10 - line:8:18] RangeText=".C(S(.A))"
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
rob@Resonance ~/Desktop> swiftc boom.swift; and ./boom
boom.swift:8:3: error: keyword 'self' cannot be used as an identifier
                self = .C(S(.A))
                ^
Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.52.2/src/llvm/include/llvm/Support/Casting.h, line 95.
0  swift                    0x0000000111538bbb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x00000001115392fb SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff9644deaa _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff00000000 _sigtramp + 1773871472
4  libsystem_c.dylib        0x00007fff985183fb abort + 129
5  libsystem_c.dylib        0x00007fff984dfa44 basename + 0
6  swift                    0x000000010fb36bd1 (anonymous namespace)::FailureDiagnosis::typeCheckArbitrarySubExprIndependently(swift::Expr*, bool) + 353
7  swift                    0x000000010fb35988 (anonymous namespace)::FailureDiagnosis::diagnoseGeneralFailure() + 328
8  swift                    0x000000010fb329c5 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 10533
9  swift                    0x000000010fb2d28b swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 923
10 swift                    0x000000010fb2e6e7 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*, bool) + 4343
11 swift                    0x000000010fb94b30 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 784
12 swift                    0x000000010fb9a502 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 450
13 swift                    0x000000010fb34a00 (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, bool) + 384
14 swift                    0x000000010fb2d202 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 786
15 swift                    0x000000010fb2e6e7 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*, bool) + 4343
16 swift                    0x000000010fb94b30 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 784
17 swift                    0x000000010fb9a502 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 450
18 swift                    0x000000010fb9b223 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*) + 99
19 swift                    0x000000010fb9b3c4 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int) + 244
20 swift                    0x000000010fbb718b validatePatternBindingDecl(swift::TypeChecker&, swift::PatternBindingDecl*, unsigned int) + 875
21 swift                    0x000000010fbb395e (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 558
22 swift                    0x000000010fbb3718 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 152
23 swift                    0x000000010fbfe3d4 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 420
24 swift                    0x000000010fbfd789 (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 25
25 swift                    0x000000010fbfccef swift::TypeChecker::typeCheckConstructorBodyUntil(swift::ConstructorDecl*, swift::SourceLoc) + 879
26 swift                    0x000000010fbfc655 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 37
27 swift                    0x000000010fbfd38a swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 138
28 swift                    0x000000010fb8267c typeCheckFunctionsAndExternalDecls(swift::TypeChecker&) + 220
29 swift                    0x000000010fb834a9 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int) + 1913
30 swift                    0x000000010f989c28 swift::CompilerInstance::performSema() + 4152
31 swift                    0x000000010f4f950c performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 748
32 swift                    0x000000010f4f8fc8 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2728
33 swift                    0x000000010f4f502f main + 2015
34 libdyld.dylib            0x00007fff94b775ad start + 1
Stack dump:
0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file boom.swift -target x86_64-apple-darwin15.0.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -color-diagnostics -module-name boom -o /var/folders/9y/f7n4rvx901nctm_5d16c1wm40000gn/T/boom-8b478e.o 
1.	While type-checking 'init' at boom.swift:6:2
2.	While type-checking declaration 0x7fbc1287bd48 at boom.swift:7:3
3.	While type-checking expression at [boom.swift:8:10 - line:8:18] RangeText=".C(S(.A))"
4.	While type-checking expression at [boom.swift:8:10 - line:8:18] RangeText=".C(S(.A))"


Regression:
It doesn’t crash if you comment out the let line, or if you don’t recur through another type (S), or if you fully qualify the argument to S.init as E.A instead of .A.

Notes:
N/A

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!