Skip to content

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

@swift-ci

Description

@swift-ci
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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselffeatureA feature request or implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions