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-4270] Useless diagnostic when passing expression of wrong type to function #46853

Closed
NachoSoto opened this issue Mar 17, 2017 · 8 comments
Closed
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

@NachoSoto
Copy link
Contributor

Previous ID SR-4270
Radar rdar://problem/33914503
Original Reporter @NachoSoto
Type Bug
Status Closed
Resolution Cannot Reproduce
Environment

Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)

Swift version 4.0 (swiftlang-900.0.59 clang-900.0.34.2)

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

md5: 5fb54fccdf2077876f40a43fd14ae467

Issue Description:

Code:

let x: Bool = true
enum A { 
    case a
    case b
}
func f(_ a: A) {}
let a: A = .a
f(x ? .a(a) : .b)

Result:
error: repl.swift:8:13: error: result values in '? :' expression have mismatching types '' and ''
f(x ? .a(a) : .b)
~~~~~ ^ ~~

This is a reduction of a case I saw in my code. In the real code I got "Int1 is not convertible to 'Bool'", but I'm not sure why that was different, other than the fact that it's inside of a closure inside of another closure...

@belkadan
Copy link
Contributor

3.1 goes back to giving up completely: "type of expression is ambiguous without more context"

@NachoSoto
Copy link
Contributor Author

Still an issue in Swift 4.0

@slavapestov
Copy link
Member

@swift-ci create

@mdiep
Copy link
Contributor

mdiep commented Jul 8, 2018

Swift 4.2 gives a good diagnostic here:

4270.swift:8:8: error: member 'a' takes no arguments
f(x ? .a(a) : .b)
       ^~~~

@belkadan
Copy link
Contributor

belkadan commented Jul 9, 2018

Could probably still be better, but yeah, that's way closer to what we want.

@mdiep
Copy link
Contributor

mdiep commented Jul 9, 2018

@belkadan Do you have anything specific in mind? I can take a look at improving it if you have any suggestions.

@belkadan
Copy link
Contributor

belkadan commented Jul 9, 2018

I was thinking that it could be special-cased for enum elements, something like "enum element 'a' does not have an associated value".

@hborla
Copy link
Member

hborla commented Apr 8, 2020

This produces

error: enum case 'a' has no associated values
f(x ? .a(a) : .b)
       ^

on master (and maybe Swift 5.2 but I didn't try)

@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

5 participants