Files
swift-mirror/validation-test/compiler_crashers_2_fixed/rdar73169149.swift
Slava Pestov c8aee4180e Sema: Fix a couple of crash-on-invalid problems with class inheritance
It is possible for ClassDecl::getSuperclassDecl() to succeed but for
ClassDecl::getSuperclass() to fail. This happens if the superclass is
a generic type and one of the generic arguments could not be resolved,
or does not satisfy the generic requirements, for example; in that
case, a BoundGenericType cannot be formed.

In a couple of places we were not prepared for this possibility.
Let's recover by making judicious use of ErrorType.

Fixes <rdar://problem/73169149>.
2021-01-17 18:06:13 -05:00

27 lines
553 B
Swift

// RUN: not %target-swift-frontend -emit-ir %s
public protocol Ungulate {
func eat()
}
public class Horse<T> : Ungulate {
public var saddle: AnyObject? = nil
public func eat() {}
}
public struct Hay {}
// Here, ClassDecl::getSuperclassDecl() will find the 'Horse' class, but
// ClassDecl::getSuperclass() will return ErrorType because the generic
// argument 'DoesNotExist' cannot be resolved.
public class Pony : Horse<DoesNotExist> {
public override var saddle: AnyObject? {
didSet {}
}
public func eat(_: Hay) {
eat()
}
}