Skip to content

[CSGen] Add a null check to prevent using invalid superclass type #33083

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
merged 1 commit into from
Jul 24, 2020
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
3 changes: 3 additions & 0 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2994,6 +2994,9 @@ namespace {
typeContext->getDeclaredInterfaceType());
auto superclassTy = selfTy->getSuperclass();

if (!superclassTy)
return Type();

if (selfDecl->getInterfaceType()->is<MetatypeType>())
superclassTy = MetatypeType::get(superclassTy);

Expand Down
9 changes: 9 additions & 0 deletions test/Constraints/super_method.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ func use_d(_ d: D) -> Int {
func not_method() {
super.foo() // expected-error{{'super' cannot be used outside of class members}}
}

// rdar://problem/50819554 - inability to properly resolve superclass shouldn't crash the solver
func test_that_invalid_supertype_ref_doesnt_crash() {
final class Node: ManagedBuffer<AnyObject, Undefined> { // expected-error {{cannot find type 'Undefined' in scope}}
static func create() {
super.create()
}
}
}