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-10724] Opaque Result Type on setter of computed property can not compile #53121

Open
omochi opened this issue May 21, 2019 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself opaque types Feature → types: opaque types

Comments

@omochi
Copy link
Collaborator

omochi commented May 21, 2019

Previous ID SR-10724
Radar None
Original Reporter @omochi
Type Bug
Environment

swift-DEVELOPMENT-SNAPSHOT-2019-05-15-a.

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

md5: 4ad9b24159d34e1b30e2ef152479ad4b

Issue Description:

[omochi@omochi-iMac-PC43 check]$ cat c3.swift
public protocol P { }
private struct Impl: P { }

public struct Vendor {
    private var storage: [Impl] = [Impl()]
    
    public var count: Int {
        return storage.count
    }
    
    public subscript(index: Int) -> some P {
        get {
            return storage[index]
        }
        set (newValue) {
            storage[index] = newValue
        }
    }
}

var vendor = Vendor()
vendor[0] = vendor[2] // ok: can move elements around
[omochi@omochi-iMac-PC43 check]$ swift c3.swift
c3.swift:16:30: error: cannot assign value of type 'some P' to type 'Impl'
            storage[index] = newValue
                             ^~~~~~~~
                                      as! Impl

Setter need to force cast.
It is bug.

This code is in proposal document.
https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md

@belkadan
Copy link
Contributor

cc @jckarter

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 in itself opaque types Feature → types: opaque types
Projects
None yet
Development

No branches or pull requests

2 participants