Skip to content
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

[SR-6173] Problems with generics + AnyObject or class protocol conformance #48725

Closed
swift-ci opened this issue Oct 17, 2017 · 2 comments
Closed

[SR-6173] Problems with generics + AnyObject or class protocol conformance #48725

swift-ci opened this issue Oct 17, 2017 · 2 comments

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Oct 17, 2017

Previous ID SR-6173
Radar None
Original Reporter kzaher (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9.0 (9A235)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 362b25ce7419a359dc62947eb9a90861

duplicates:

  • SR-55 non-@objc protocol existentials do not conform to their own protocol type

Issue Description:

Test cases:

This fails to compile
```
public protocol MyDelegate: AnyObject {
}

class A<P1: AnyObject> {
init(param: P1) { }
}

func prettyPleaseMakeItCompile() {
let a: MyDelegate = (nil as MyDelegate?)!
A(param: a)
}
```

This also fails to compile:
```
public protocol MyDelegate: class {
}

class A<P1: AnyObject> {
init(param: P1) { }
}

func prettyPleaseMakeItCompile() {
let a: MyDelegate = (nil as MyDelegate?)!
A(param: a)
}
```

but this compiles
```
@objc public protocol MyDelegate {
}

class A<P1: AnyObject> {
init(param: P1) { }
}

func prettyPleaseMakeItCompile() {
let a: MyDelegate = (nil as MyDelegate?)!
A(param: a)
}
```

and this also does

```
public protocol MyDelegate: AnyObject {
}

class A<P1: AnyObject> {
init(param: P1) { }
}

class B: MyDelegate {

}

func prettyPleaseMakeItCompile() {
A(param: B())
}
```

and so does this
```
public protocol MyDelegate: class {
}

class A<P1: AnyObject> {
init(param: P1) { }
}

class B: MyDelegate {

}

func prettyPleaseMakeItCompile() {
A(param: B())
}
```

Expected result, all provided code snippets should compile successfully.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Oct 17, 2017

Comment by Krunoslav Zaher (JIRA)

I've also checked with Xcode 9.0.1 (9A1004) and it doesn't work there either.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Oct 20, 2017

The problem is that a protocol value isn't just a single reference-counted object value like AnyObject; it also stores a pointer to the conformance. @objc protocols are exempt from this because everything just goes through the Objective-C runtime, but it's not something that applies generally in Swift.

@slavapestov has a dup of this.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants