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-5713] Ambiguous Parsing of typeof #48283

Closed
swift-ci opened this issue Aug 18, 2017 · 4 comments
Closed

[SR-5713] Ambiguous Parsing of typeof #48283

swift-ci opened this issue Aug 18, 2017 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation regression swift 4.0 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5713
Radar rdar://problem/34003460
Original Reporter aaroncrespo (JIRA User)
Type Bug
Status Resolved
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.0Regression, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 397d1ff7356617f91aee603d16fa1235

Issue Description:

Sometimes type(of: ) needs a little help

extension Int {
  var type: String {
    return "Integer"
  }

  func out() -> String {
    return "\(type(of: self))"
  }
}

1.out() // doesnt work
"\(type(of: 1))" // works
"\(1.type)" // works
@swift-ci
Copy link
Collaborator Author

Comment by aaron crespo (JIRA)

you can disambiguate with `Swift.type(of: )`

Additionally the code sample here:

https://developer.apple.com/documentation/swift/2885064-type?changes=latest_minor

fails with a similar issue

@ematejska
Copy link
Mannequin

ematejska mannequin commented Aug 22, 2017

This does seem to have worked in Xcode 8.3.3.

@swift-ci create

@belkadan
Copy link
Contributor

This is correct. type(of:) is just a function in Swift 4. It doesn't do anything special. That means it can be shadowed like any other top-level function. (There are existing bugs for improving that experience.)

@swift-ci
Copy link
Collaborator Author

Comment by aaron crespo (JIRA)

Note that I used Int just as a means to reduce the test case. It happens on all types.

Is it shadowing within the instance if one is a property and one is a function? I thought they were distinct?

With

let list = [1,2,3,45,5]
let types1 = list.map { $0.type } // works
let types2 = list.map(Int.type) // doesn't work as expected member is not a function
let types3 = list.map { $0[keyPath: \Int.type] } // works
let types4 = list.map(type) // doesn't work with different error from types2 reference to Swift.type not implemented.

Compiles with two different errors, if shadowing was happening and was the cause of this wouldnt I expect the same error?

@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. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation regression swift 4.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants