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-7143] Compiler chooses custom function over foundation function #49691

Open
swift-ci opened this issue Mar 8, 2018 · 5 comments
Open

[SR-7143] Compiler chooses custom function over foundation function #49691

swift-ci opened this issue Mar 8, 2018 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 8, 2018

Previous ID SR-7143
Radar None
Original Reporter JaydenIrwin (JIRA User)
Type Bug
Status Reopened
Resolution
Environment

Xcode 9.2 (9C40b)

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

md5: 4c28b84f29e37659e8b32c80830a5b72

Issue Description:

I am unable to compile this code. I'm given the error "Missing arg for parameter 'of' in call". And syntax highlighting shows the "log" function is custom, not from the standard libraries.

func log(base: Double, of value: Double) -> Double {
    return log(value) / log(base) //error
}
@belkadan
Copy link
Contributor

belkadan commented Mar 8, 2018

log isn't part of the standard library; you'll have to import Darwin/Glibc first. (Or just Foundation.)

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 9, 2018

Comment by Jayden Irwin (JIRA)

I was importing SpriteKit, now I'm also importing Foundation, still not compiling.

@belkadan
Copy link
Contributor

belkadan commented Mar 9, 2018

It works for me. Can you attach a sample project?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 9, 2018

Comment by Jayden Irwin (JIRA)

import Foundation
import SpriteKit

class Foo {
 
 init() {
     func log(base: Double, of value: Double) -> Double {
         return log(value) / log(base)
     }
 }

}

@jepers
Copy link

jepers commented Mar 9, 2018

Note that while the following compiles as expected:

import Foundation
import SpriteKit

func log(base: Double, of value: Double) -> Double {
    return log(value) / log(base)
}

Jayden Irwin's example will not:

import Foundation
import SpriteKit

class Foo {
    init() {
        func log(base: Double, of value: Double) -> Double {
            return log(value) / log(base) // Missing arg for param 'of'
        }
    }
}

As will not this:

import Foundation
import SpriteKit

func outer() {
    func log(base: Double, of value: Double) -> Double {
            return log(value) / log(base) // Missing arg for param 'of'
    }
}

I guess this is (somewhat surprisingly) working as intended, and is essentially the same as
https://bugs.swift.org/browse/SR-7018

So you'll have to use Darwin.log iff your log(base: of: ) func is not in global scope : )

@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

3 participants