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-12227] Ambiguous reference to member 'random(in:using:)' for BinaryFloatingPoint protocol #54653

Closed
swift-ci opened this issue Feb 18, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12227
Radar None
Original Reporter difomiry (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.0.0

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

md5: 03afcbc561a4fbcb12abaf1969d8399b

Issue Description:

My code:

extension Collection where Element: BinaryFloatingPoint {
  var random: Element {
    Element.random(in: 0...1)
  }
}

Log:

/tmp/42407C3B-C2C5-4563-A7C1-8EE429F26D38.53repj/main.swift:5:5: error: ambiguous reference to member 'random(in:using:)'
    Element.random(in: 0...1)
    ^~~~~~~
Swift.BinaryFloatingPoint:5:35: note: found this candidate
    @inlinable public static func random<T>(in range: Range<Self>, using generator: inout T) -> Self where T : RandomNumberGenerator
                                  ^
Swift.BinaryFloatingPoint:6:35: note: found this candidate
    @inlinable public static func random(in range: Range<Self>) -> Self
                                  ^
Swift.BinaryFloatingPoint:7:35: note: found this candidate
    @inlinable public static func random<T>(in range: ClosedRange<Self>, using generator: inout T) -> Self where T : RandomNumberGenerator
                                  ^
Swift.BinaryFloatingPoint:8:35: note: found this candidate
    @inlinable public static func random(in range: ClosedRange<Self>) -> Self

Related issues:
https://bugs.swift.org/browse/SR-8156
#17716
#17766

@swift-ci
Copy link
Collaborator Author

Comment by Dmitry Fomin (JIRA)

I found solution. You need to add "Element.RawSignificand: FixedWidthInteger" constraint:

extension Collection where Element: BinaryFloatingPoint, Element.RawSignificand: FixedWidthInteger {
  var random: Element {
    Element.random(in: 0...1)
  }
}

@hborla
Copy link
Member

hborla commented Feb 21, 2020

@swift-ci create

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants