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-14844] Static member func Set<X> parameter sometimes cannot convert from array literal #57191

Open
mattyoung opened this issue Jun 28, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@mattyoung
Copy link

Previous ID SR-14844
Radar rdar://problem/79921692
Original Reporter @mattyoung
Type Bug
Environment

Xcode Version 13.0 beta (13A5155e)

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

md5: 981f73b357d0583a02a72282ffe203c2

Issue Description:

import Foundation
import SwiftUI

// `fields` parameter is correctly converted from array literal to Set<Field>
let _ :Date.ComponentsFormatStyle  = .components(style: .abbreviated, fields: [.minute])
//                                                                            ^^^^^^^^^
let range = Date.now ..< Date.now
#warning("`fields` do not compile from array literal")
range.formatted(.components(style: .abbreviated, fields: [.minute]))
//                                                       ^^^^^^^^^
// compile error:
// Cannot convert value of type '[Any]' to expected argument type 'Set<Date.ComponentsFormatStyle.Field>?'
// Reference to member 'minute' cannot be resolved without a contextual type

// fields: add explicit .init then compile, should not need to add .init()
range.formatted(.components(style: .abbreviated, fields: .init([.minute])))
//                                                       ^^^^^

// same problem with SwiftUI Text:
// this do not compile:
Text(range, format: .components(style: .abbreviated, fields: [.minute]))
// this is fine:
Text(range, format: .components(style: .abbreviated, fields: .init([.minute])))

// this do not compile:
Text("\(range, format: .components(style: .abbreviated, fields: [.minute]))")
// this is fine:
Text("\(range, format: .components(style: .abbreviated, fields: .init([.minute])))")
@typesanitizer
Copy link

The range.formatted example works on main, so maybe that fix should be cherry-picked to 5.5. The others don't work, and I even see odd diagnostics such as error: incorrect argument label in call (have ':format:', expected ':formatter:').

@swift-ci create

@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.
Projects
None yet
Development

No branches or pull requests

2 participants