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-456] Confusing build error when calling 'max' function within 'extension Int' #43073

Closed
swift-ci opened this issue Jan 4, 2016 · 3 comments
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

swift-ci commented Jan 4, 2016

Previous ID SR-456
Radar None
Original Reporter kyleve (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode Version: Version 7.2 (7C68)
OS X Version: 10.11.1 (15B42)

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

md5: c80716cfb9eccad98f648bc05dc3a005

is duplicated by:

  • SR-609 'Cannot call value of non-function type' error when calling initializer of class with same name as enum case

relates to:

  • SR-5594 Unexpected error: Cannot call value of non-function type 'Data?'

Issue Description:

When trying to build code that calls max() within an extension Int, a compiler error occurs.

import Foundation


func thisWorksCorrectly()
{
    let maxValue = max(0, 1)
}

internal extension Int
{
    static func thisDoesNotBuild()
    {
       // Error: Cannot call value of non-function type 'Int'
        let maxValue = max(0, 1)
    }
    
    static func butThisDoesBuild()
    {
        let maxValue = Swift.max(0, 1)
    }
}

This problem can be worked around by changing max(0, 1) to Swift.max(0, 1), but the error message seems unclear.

@belkadan
Copy link
Contributor

This is technically "behaves-as-designed": if any matches for a name are found in an inner context, the outer context is not searched. But enough people have been unhappy with this that we could consider changing it. The discussion should probably happen on the swift-evolution list, though I'm not sure if it'll need a full proposal.

@swift-ci
Copy link
Collaborator Author

Comment by Kyle Van Essen (JIRA)

FWIW, I think the behavior is fine; it was just the error message that threw me off for a while. A "Did you mean Swift.max?" would be more than enough.

(I'm going to update the ticket since I totally didn't convey that at all.)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis
Copy link
Collaborator

This is diagnosed accurately now, and backed up with tests here—closing.

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

3 participants