-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Disallow conditional conformances on objective-c generics. #14628
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//===- TypeOrExtensionDecl.h - Swift Language Declaration ASTs -*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the TypeOrExtensionDecl struct, separately to Decl.h so | ||
// that this can be included in files that Decl.h includes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_TYPE_OR_EXTENSION_DECL_H | ||
#define SWIFT_TYPE_OR_EXTENSION_DECL_H | ||
|
||
#include "swift/AST/TypeAlignments.h" | ||
#include "llvm/ADT/PointerUnion.h" | ||
|
||
namespace swift { | ||
|
||
/// \brief Describes either a nominal type declaration or an extension | ||
/// declaration. | ||
struct TypeOrExtensionDecl { | ||
// (The definitions are in Decl.cpp.) | ||
llvm::PointerUnion<NominalTypeDecl *, ExtensionDecl *> Decl; | ||
|
||
TypeOrExtensionDecl() = default; | ||
|
||
TypeOrExtensionDecl(NominalTypeDecl *D); | ||
TypeOrExtensionDecl(ExtensionDecl *D); | ||
|
||
/// \brief Return the contained *Decl as the Decl superclass. | ||
class Decl *getAsDecl() const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stray There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field is called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I guess I would have just renamed the field. |
||
/// \brief Return the contained *Decl as the DeclContext superclass. | ||
DeclContext *getAsDeclContext() const; | ||
/// \brief Return the contained NominalTypeDecl or that of the extended type | ||
/// in the ExtensionDecl. | ||
NominalTypeDecl *getBaseNominal() const; | ||
|
||
/// \brief Is the contained pointer null? | ||
bool isNull() const; | ||
explicit operator bool() const { return !isNull(); } | ||
|
||
bool operator==(TypeOrExtensionDecl rhs) { return Decl == rhs.Decl; } | ||
bool operator!=(TypeOrExtensionDecl rhs) { return Decl != rhs.Decl; } | ||
bool operator<(TypeOrExtensionDecl rhs) { return Decl < rhs.Decl; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this one makes sense to provide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just mindlessly duplicating the |
||
}; | ||
|
||
} // end namespace swift | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@import Foundation; | ||
|
||
@interface ObjC <ObjectType>: NSObject | ||
@end | ||
|
||
@interface ObjC2: NSObject | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: %target-typecheck-verify-swift -import-objc-header %S/Inputs/conditional_conformances_objc.h | ||
|
||
// REQUIRES: objc_interop | ||
|
||
protocol Foo {} | ||
extension ObjC: Foo where ObjectType == ObjC2 {} | ||
// expected-error@-1{{type 'ObjC<ObjectType>' cannot conditionally conform to protocol 'Foo' because the type uses the Objective-C generics model}} | ||
|
||
protocol Bar {} | ||
extension ObjC: Bar where ObjectType: Bar {} | ||
// expected-error@-1{{type 'ObjC<ObjectType>' cannot conditionally conform to protocol 'Bar' because the type uses the Objective-C generics model}} | ||
|
||
extension ObjC { | ||
struct Struct { | ||
enum Enum {} | ||
} | ||
class Class<T> {} | ||
} | ||
|
||
extension ObjC.Struct: Foo where ObjectType == ObjC2 {} | ||
// expected-error@-1{{type 'ObjC<ObjectType>.Struct' cannot conditionally conform to protocol 'Foo' because the type uses the Objective-C generics model}} | ||
extension ObjC.Struct: Bar where ObjectType: Bar {} | ||
// expected-error@-1{{type 'ObjC<ObjectType>.Struct' cannot conditionally conform to protocol 'Bar' because the type uses the Objective-C generics model}} | ||
|
||
extension ObjC.Struct.Enum: Foo where ObjectType == ObjC2 {} | ||
// expected-error@-1{{type 'ObjC<ObjectType>.Struct.Enum' cannot conditionally conform to protocol 'Foo' because the type uses the Objective-C generics model}} | ||
extension ObjC.Struct.Enum: Bar where ObjectType: Bar {} | ||
// expected-error@-1{{type 'ObjC<ObjectType>.Struct.Enum' cannot conditionally conform to protocol 'Bar' because the type uses the Objective-C generics model}} | ||
|
||
extension ObjC.Class: Foo where T == ObjC2 {} | ||
// expected-error@-1{{type 'ObjC<ObjectType>.Class<T>' cannot conditionally conform to protocol 'Foo' because the type uses the Objective-C generics model}} | ||
extension ObjC.Class: Bar where T: Bar {} | ||
// expected-error@-1{{type 'ObjC<ObjectType>.Class<T>' cannot conditionally conform to protocol 'Bar' because the type uses the Objective-C generics model}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably doesn't actually work, because PointerUnion needs to know the alignment of the types in it to know where to stick spare bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to compile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It compiles as long as you also include Decl.h before the template actually has to be instantiated, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I address this then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untangle the headers? Or…ah, it looks like we have swift/AST/TypeAlignments.h for this. ASTNode.h uses it in a similar way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat; changed it to use that header.