Skip to content

IRGen: Deal with broken AST from batch mode #29926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,9 +1836,12 @@ const TypeInfo *TypeConverter::convertType(CanType ty) {
PrettyStackTraceType stackTrace(IGM.Context, "converting", ty);

switch (ty->getKind()) {
case TypeKind::Error:
llvm_unreachable("found an ErrorType in IR-gen");

case TypeKind::Error: {
// We might see error types if type checking has failed.
// Try to do something graceful and return an zero sized type.
auto &ctx = ty->getASTContext();
return convertTupleType(cast<TupleType>(ctx.TheEmptyTupleType));
}
#define UNCHECKED_TYPE(id, parent) \
case TypeKind::id: \
llvm_unreachable("found a " #id "Type in IR-gen");
Expand Down
14 changes: 14 additions & 0 deletions test/IRGen/Inputs/batchmode_errors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

@objc
protocol SomeProto {
func conform()
}

class AnotherClass {}

class SomeClass {
// Intentionally referencing the wrong class name.
var x : AnotherClass2? = nil
}

11 changes: 11 additions & 0 deletions test/IRGen/batchmode_ast_errors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: not %target-swift-frontend -primary-file %s %S/Inputs/batchmode_errors.swift -emit-ir 2>&1 | %FileCheck %s

// REQUIRES: objc_interop

// Verify that we don't crash (in IRGen).

// CHECK-NOT: Stack dump

extension SomeClass : SomeProto {
func conform() {}
}