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-8762] Array of NSNumber inferred as UnsafeRawPointer. #51270

Open
swift-ci opened this issue Sep 15, 2018 · 1 comment
Open

[SR-8762] Array of NSNumber inferred as UnsafeRawPointer. #51270

swift-ci opened this issue Sep 15, 2018 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8762
Radar None
Original Reporter freak4pc (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 9.4.1 & Xcode 10 GM

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

md5: 1263fc95de2adf4964240ae18f3c6116

Issue Description:

When using the following generic function:

func cmp<T>(_ lhs: T, _ rhs: T, _ comparison: (T, T) -> Bool) -> Bool {
    return comparison(lhs, rhs)
}

And passing in an array of `NSNumber`s , `T` is inferred as `UnsafeRawPointer` instead of `[NSNumber]`:

func cmp<T>(_ lhs: T, _ rhs: T, _ comparison: (T, T) -> Bool) -> Bool {
    print(#line, type(of: lhs), type(of: rhs))
    return comparison(lhs, rhs)
}

// false (inferred as UnsafeRawPointer)
print(#line, cmp([NSNumber(value: -5)], [NSNumber(value: -5)]) { $0 == $1 })

// true (explicit type as [NSNumber])
print(#line, cmp([NSNumber(value: -5)] as [NSNumber], [NSNumber(value: -5)]) { $0 == $1 })

// true
print(#line, [NSNumber(value: -5)] == [NSNumber(value: -5)])

Output:

18 UnsafeRawPointer UnsafeRawPointer
27 false
18 Array<NSNumber> Array<NSNumber>
29 true
32 true
35 true

Screenshot might be easier to look at 🙂

@belkadan
Copy link
Contributor

@rudkx, we have others of these, right? Although until we got conditional conformances this was probably the only choice.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants