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-453] Structs, Protocols and casting #43070

Closed
swift-ci opened this issue Jan 3, 2016 · 2 comments · Fixed by #59535
Closed

[SR-453] Structs, Protocols and casting #43070

swift-ci opened this issue Jan 3, 2016 · 2 comments · Fixed by #59535
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself feature A feature request or implementation

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Jan 3, 2016

Previous ID SR-453
Radar None
Original Reporter flashspys (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, LanguageFeatureRequest
Assignee None
Priority Medium

md5: 973efe727beed10b6f2ae35767f6d7b6

Issue Description:

I don't like the way how Swift handles structs which implements protocols:

Simple demonstration:

protocol Prot {}
struct A : Prot {}

let arr = [A(), A()] // 1: ok
let arr2 = [A(), A()] as [Prot] // 2: ok
let arr3 = arr as [Prot] // 3: compile error
let arr4 = arr2 as! [A] // 4: runtime error

It was discussed here. I think it's mandatory to support casting here and should not be a language limitation. I really like structs in swift but it is very hard to implement sth. like a hierarchy of structs cause they can't inherit from each other and it's hard to work with protocols as you see above.

Does anyone feels similar ?

@Dante-Broggi
Copy link
Contributor

I think this can be closed, neither error occurs in the Xcode 9.4.1 toolchain.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Jun 22, 2022

We got test coverage for this here—expect for the arr4 case, which expectedly works, but I'm going to add it for the record anyway before closing.

AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 22, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 22, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 23, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself feature A feature request or implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants