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-13306] Incorrect shadowing behavior for local functions and outer function parameters #55746

typesanitizer opened this issue Jul 28, 2020 · 2 comments


Copy link

@typesanitizer typesanitizer commented Jul 28, 2020

Previous ID SR-13306
Radar rdar://problem/66190794
Original Reporter @typesanitizer
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 7c03e3d2a0ccfe87deedce1a98b39190


  • SR-10069 Local functions cannot be overloaded

relates to:

  • SR-14242 Type-checking incorrect when local function and variable share the same name

Issue Description:

func g(_ f: () -> ()) {
    func f(_ x: Int) {}
    f() // okay
    f(10) // error: argument passed to call that takes no arguments

This is not right. I think the correct behavior here would be to have the first call not compile and have the second call compile. That is what you would get if you instead had

func g(_ f: () -> ()) {
    let f = { (x: Int) in () }
    f() // error: missing argument for parameter #​1 in call
    f(10) // okay
Copy link

@typesanitizer typesanitizer commented Jul 28, 2020

Ideally, we would have shadowing test cases for the full matrix.

  1. Parameter shadowed by local function

  2. Parameter shadowed by let

  3. local function shadowed by let

  4. let shadowed by local function

  5. let shadowed by parameter

  6. local function shadowed by parameter

and the 3 diagonal elements. (Feel free to add more stuff that's missing. 🙂)

Copy link

@typesanitizer typesanitizer commented Jul 28, 2020

@swift-ci create

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

No branches or pull requests

1 participant