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-6214] compiler cannot disambiguate variable named type from the function type(of:) #48766

Closed
swift-ci opened this issue Oct 24, 2017 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-6214
Radar None
Original Reporter rexmas (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Environment

Swift 4

Xcode 9.0

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

md5: 5b631c25ff45ffe50aeaa87ad2ef789d

relates to:

  • SR-1772 File-level function with the same name as instance function not picked up by compiler

Issue Description:

This code worked in Swift 3

func log(_ message: String, _ loggedType: Any? = nil) {
    var type: String? = nil
    if let loggedType = loggedType {
        type = "\(type(of: loggedType))"
    }
    
    ///... log the message and type
}

log("this is a log", String.self)

In swift 4 I get the following error on `type(of: loggedType)`

Cannot call value of non-function type 'String?'

It seems as if it things `type(of🙂` is trying to call on the variable `type` that I just declared.

@belkadan
Copy link
Contributor

That's correct behavior. type(of:) is just a normal function in the standard library in Swift 4.

@belkadan
Copy link
Contributor

You can use Swift.type(of: …) to disambiguate.

@swift-ci
Copy link
Collaborator Author

Comment by Rex Fenley (JIRA)

fancy, thanks 👍

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

No branches or pull requests

2 participants