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-9970] Type inference for literals in argument position depends on whether parameter is named #52374

Closed
swift-ci opened this issue Feb 21, 2019 · 6 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

Previous ID SR-9970
Radar rdar://problem/48295187
Original Reporter nschum (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 921b244301ef8cfa8e42e5e347683f38

cloned to:

  • SR-9901 Deserialization Failure: Result not found. Cross-reference to module 'App'

Issue Description:

func foo(_ arg: Any) { print(1) }
func foo(_ arg: [Any]) { print(2) }

func foo(arg: Any) { print(3) }
func foo(arg: [Any]) { print(4) }

foo([0])
foo(arg: [0])

This prints 1 and 4, which is somewhat surprising.

It looks like the type of [0] is inferred as [Int] and then as [Any]. But the type shouldn't depend on whether the parameter is named, should it?

@belkadan
Copy link
Contributor

cc @xedin

@xedin
Copy link
Member

xedin commented Feb 22, 2019

nschum (JIRA User) Hm, it looks like `_: [Any]` overload is not even matched by type-checker, this looks like a bug.

@xedin
Copy link
Member

xedin commented Feb 22, 2019

danielbrownk31 (JIRA User) Can you mention PR which fixed this? I don't think this has been resolved.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 1, 2019

Comment by Nikolaj Schumacher (JIRA)

I've downloaded the 2019-02-26 trunk snapshot and it shows the same behavior.

@DougGregor
Copy link
Member

Fixed by #23125

@swift-ci
Copy link
Collaborator Author

Comment by Nikolaj Schumacher (JIRA)

@DougGregor Thank you, I can confirm the fix.

However, it seems to also have changed certain edge cases regarding Any I've described in SR-6533. While the new behavior makes much more sense to me, I'm letting you know, in case you feel this was unintended or needs to go through evolution.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants