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-7644] Unexpected errors about argument labels when passing a reference to a private method to a function #50185

Closed
bdash opened this issue May 10, 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 type checker Area → compiler: Semantic analysis

Comments

@bdash
Copy link
Contributor

bdash commented May 10, 2018

Previous ID SR-7644
Radar rdar://problem/40144207
Original Reporter @bdash
Type Bug
Status Resolved
Resolution Done
Environment

Seen with Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1), and with Swift built from source from dc5827c.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @bdash
Priority Medium

md5: 2162c95296299e1d292338b27a9b442e

Issue Description:

Consider this code, in which the private initializer of `S` is passed to a function as an argument of a generic type:

class C { 
 public func foo<FnType>(_ fn: FnType, bool: Bool = true) -> Self { return self } 
 public func foo<FnType>(_ fn: FnType, int: Int, bool: Bool = true) -> Self { return self } 
} 
 
struct S { 
 private init() { } 
} 
 
// Gives expected error: 'init' is inaccessible due to 'private' protection level 
C().foo(S.init) 
 
// Gives bogus error: incorrect argument label in call (have '_:int:', expected '_:bool:') 
C().foo(S.init, int: 1) 
 
// Gives bogus error: extra argument 'int' in call 
C().foo(S.init, int: 1, bool: true)
 

These are the errors that are seen:

$ swiftc test.swift 
test.swift:11:11: error: 'init' is inaccessible due to 'private' protection level
C().foo(S.init)
          ^
test.swift:7:13: note: 'init' declared here
    private init() { }
            ^
test.swift:14:8: error: incorrect argument label in call (have '_:int:', expected '_:bool:')
C().foo(S.init, int: 1)
       ^        ~~~
                bool
test.swift:16:22: error: extra argument 'int' in call
C().foo(S.init, int: 1, bool: true)
                     ^
$ 

Only the first error is what is expected. In the latter two cases the errors unexpectedly claim the argument labels are incorrect, when in fact the issue is that the initializer is inaccessible.

@belkadan
Copy link
Contributor

cc @xedin

@xedin
Copy link
Member

xedin commented May 10, 2018

@swift-ci create

@xedin
Copy link
Member

xedin commented Mar 17, 2020

@bdash Looks like this problem has been fixed in 11.4, could you please use one of the betas to verify and close?

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants