Skip to content

Commit e641c4a

Browse files
committed
IRGen: Deal with broken AST from batch mode
rdar://59552858
1 parent d842fa3 commit e641c4a

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

lib/IRGen/GenType.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,9 +1836,12 @@ const TypeInfo *TypeConverter::convertType(CanType ty) {
18361836
PrettyStackTraceType stackTrace(IGM.Context, "converting", ty);
18371837

18381838
switch (ty->getKind()) {
1839-
case TypeKind::Error:
1840-
llvm_unreachable("found an ErrorType in IR-gen");
1841-
1839+
case TypeKind::Error: {
1840+
// We might see error types if type checking has failed.
1841+
// Try to do something graceful and return an zero sized type.
1842+
auto &ctx = ty->getASTContext();
1843+
return convertTupleType(cast<TupleType>(ctx.TheEmptyTupleType));
1844+
}
18421845
#define UNCHECKED_TYPE(id, parent) \
18431846
case TypeKind::id: \
18441847
llvm_unreachable("found a " #id "Type in IR-gen");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Foundation
2+
3+
@objc
4+
protocol SomeProto {
5+
func conform()
6+
}
7+
8+
class AnotherClass {}
9+
10+
class SomeClass {
11+
// Intentionally referencing the wrong class name.
12+
var x : AnotherClass2? = nil
13+
}
14+

test/IRGen/batchmode_ast_errors.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: not %target-swift-frontend -primary-file %s %S/Inputs/batchmode_errors.swift -emit-ir 2>&1 | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// Verify that we don't crash (in IRGen).
6+
7+
// CHECK-NOT: Stack dump
8+
9+
extension SomeClass : SomeProto {
10+
func conform() {}
11+
}

0 commit comments

Comments
 (0)