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-9096] If a variable shadows a function, the diagnostic when attempting to invoke the variable like a function should suggest to rename the variable or qualify the function #51593

Open
millenomi opened this issue Oct 27, 2018 · 3 comments
Assignees
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

Comments

@millenomi
Copy link
Contributor

Previous ID SR-9096
Radar rdar://problem/45643783
Original Reporter @millenomi
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee @xedin
Priority Medium

md5: 0a5b8207de16c157bcc3a6ef6654c687

is duplicated by:

  • SR-9575 Compiler ignores global function to view error message in some situations.
  • SR-10136 Unclear error message after shadowing type(of:) function

relates to:

  • SR-1687 Swift does not warn about shadowing

Issue Description:

If I have code of the form:

let type = "Not A Function"; let x = 42; type(of: x)

currently the diagnostic says:

error: repl.swift:1:46: error: cannot call value of non-function type 'String'
let type = "Not A Function"; let x = 42; type(of: x)
                                         ~~~~^

If the function call would match a callable were the variable not the closest match, this message should have fix-its of the form:

  • 'Please rename the "type" variable', and

  • 'Please qualify the function call with <Module name>', e.g. suggesting "Swift.type(of: x)" instead in the example.

@belkadan
Copy link
Contributor

I know we have some similar diagnostic in another context. @xedin?

@xedin
Copy link
Member

xedin commented Oct 29, 2018

Yes, this is shadowing diagnostics, maybe we can diagnose this kind of behavior with shadowing fix, that would be really nice...

@xedin
Copy link
Member

xedin commented Oct 29, 2018

@swift-ci create

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

3 participants