Skip to content

Sema: More ITC fixes #6186

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 3 commits into from
Dec 10, 2016
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
4 changes: 4 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,10 @@ ObjCClassKind ClassDecl::checkObjCAncestry() const {
if (!CD->hasSuperclass())
break;
CD = CD->getSuperclass()->getClassOrBoundGenericClass();
// If we don't have a valid class here, we should have diagnosed
// elsewhere.
if (!CD)
break;
}

if (!isObjC)
Expand Down
4 changes: 4 additions & 0 deletions lib/Sema/ITCNameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ bool IterativeTypeChecker::isQualifiedLookupInDeclContextSatisfied(

if (auto superclass = classDecl->getSuperclass()) {
if (auto superclassDecl = superclass->getAnyNominal()) {
// Hack.
if (superclassDecl == nominal)
return true;

if (!isSatisfied(requestQualifiedLookupInDeclContext({ superclassDecl,
payload.Name,
payload.Loc })))
Expand Down
11 changes: 5 additions & 6 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,6 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
// Set the superclass.
if (auto classDecl = dyn_cast<ClassDecl>(decl)) {
classDecl->setSuperclass(superclassTy);
if (superclassTy)
resolveImplicitConstructors(superclassTy->getClassOrBoundGenericClass());
} else if (auto enumDecl = dyn_cast<EnumDecl>(decl)) {
enumDecl->setRawType(superclassTy);
} else {
Expand Down Expand Up @@ -7859,10 +7857,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
// for all of the superclass's designated initializers.
// FIXME: Currently skipping generic classes.
auto classDecl = cast<ClassDecl>(decl);
assert(!classDecl->hasSuperclass() ||
classDecl->getSuperclass()->getAnyNominal()->isInvalid() ||
classDecl->getSuperclass()->getAnyNominal()
->addedImplicitInitializers());
if (classDecl->hasSuperclass()) {
bool canInheritInitializers = !FoundDesignatedInit;

Expand All @@ -7874,6 +7868,11 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
}

auto superclassTy = classDecl->getSuperclass();
auto *superclassDecl = superclassTy->getClassOrBoundGenericClass();
assert(superclassDecl && "Superclass of class is not a class?");
if (!superclassDecl->addedImplicitInitializers())
addImplicitConstructors(superclassDecl);

auto ctors = lookupConstructors(classDecl, superclassTy,
NameLookupFlags::IgnoreAccessibility);

Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/accessibility_vtables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class InternalSub : InternalBase {

// CHECK-LABEL: sil_vtable InternalSub {
// CHECK-NEXT: #InternalBase.method!1: _TFC21accessibility_vtables12InternalBaseP{{[0-9]+}}[[DISCRIMINATOR:_.+]]6method
// CHECK-NEXT: #InternalBase.init!initializer.1: _TFC21accessibility_vtables11InternalSubc
// CHECK-NEXT: #InternalBase.prop!getter.1: _TFC21accessibility_vtables11InternalSubg4propSi // accessibility_vtables.InternalSub.prop.getter : Swift.Int
// CHECK-NEXT: #InternalBase.prop!setter.1: _TFC21accessibility_vtables12InternalBases4propSi // accessibility_vtables.InternalBase.prop.setter : Swift.Int
// CHECK-NEXT: #InternalBase.prop!materializeForSet.1: _TFC21accessibility_vtables12InternalBasem4propSi // accessibility_vtables.InternalBase.prop.materializeForSet : Swift.Int
// CHECK-NEXT: #InternalBase.init!initializer.1: _TFC21accessibility_vtables11InternalSubc
// CHECK-NEXT: #InternalSub.method!1: _TFC21accessibility_vtables11InternalSub6method
// CHECK-NEXT: #InternalSub.prop!setter.1: _TFC21accessibility_vtables11InternalSubs4propSi // accessibility_vtables.InternalSub.prop.setter : Swift.Int
// CHECK-NEXT: #InternalSub.prop!materializeForSet.1: _TFC21accessibility_vtables11InternalSubm4propSi // accessibility_vtables.InternalSub.prop.materializeForSet : Swift.Int
Expand Down
8 changes: 4 additions & 4 deletions test/SILGen/objc_attr_NSManaged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ extension ProtoAdopter {

// The vtable should not contain any entry points for getters and setters.
// CHECK-LABEL: sil_vtable SwiftGizmo {
// CHECK-NEXT: #SwiftGizmo.modifyX!1: _TFC19objc_attr_NSManaged10SwiftGizmo7modifyX
// CHECK-NEXT: #SwiftGizmo.testFunc!1: _TFC19objc_attr_NSManaged10SwiftGizmo8testFunc
// CHECK-NEXT: #SwiftGizmo.init!initializer.1: _TFC19objc_attr_NSManaged10SwiftGizmoc
// CHECK-NEXT: #SwiftGizmo.modifyX!1: _TFC19objc_attr_NSManaged10SwiftGizmo7modifyX
// CHECK-NEXT: #SwiftGizmo.testFunc!1: _TFC19objc_attr_NSManaged10SwiftGizmo8testFunc
// CHECK-NEXT: #SwiftGizmo.deinit!deallocator:
// CHECK-NEXT: #SwiftGizmo.init!initializer.1: _TFC19objc_attr_NSManaged10SwiftGizmoc
// CHECK-NEXT: #SwiftGizmo.init!initializer.1: _TFC19objc_attr_NSManaged10SwiftGizmoc
// CHECK-NEXT: #SwiftGizmo.deinit!deallocator:
// CHECK-NEXT: }

// CHECK-LABEL: sil_vtable FinalGizmo {
Expand Down
3 changes: 2 additions & 1 deletion test/decl/class/circular_inheritance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ protocol P : P {} // expected-error{{circular protocol inheritance P}}
class Isomorphism : Automorphism { }
class Automorphism : Automorphism { } // expected-error{{circular class inheritance Automorphism}}

let _ = A()
// FIXME: Useless error
let _ = A() // expected-error{{'A' cannot be constructed because it has no accessible initializers}}

// This should probably be made to work, but for now test that it produces a crappy
// diagnostic instead of crashing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -typecheck
// RUN: not %target-swift-frontend %s -typecheck
let a{{}protocol A{class A:d class d<U:A>:A
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -typecheck
// RUN: not %target-swift-frontend %s -typecheck
struct A{init(){let:A
class B:A
class A:B{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
// REQUIRES: asserts
protocol A{enum S{var f=e
typealias f:B
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
typealias e=A.G{}{}class A:A
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
typealias e:A.d)class A:A}a
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
typealias d:A.a
class A:A