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-6623] Bad diagnostic passing array to vararg parameter with base type #49172

Closed
NachoSoto opened this issue Dec 15, 2017 · 5 comments
Closed
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-6623
Radar rdar://problem/36078499
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee owenvoorhees (JIRA)
Priority Medium

md5: 4239ebe3d957159933a87a3d7dd0aeed

Issue Description:

class Base {}
class A: Base {}
class B: Base {}

func f(_ a: [Base]) {}
func g(_ a: Base...) {}

// Works:
f([A(), B()])

// Fails with a bad diagnostic:
g([A(), B()])
error: repl.swift:10:3: error: contextual type 'Base' cannot be used with array literal
g([A(), B()])
  ^~~~~~~~~~
@NachoSoto
Copy link
Contributor Author

Actually this fails passing Base too:

g([Base()])
error: repl.swift:10:3: error: contextual type 'Base' cannot be used with array literal
g([Base()])
  ^~~~~~~~

@jckarter
Copy link
Member

@swift-ci create

@jckarter
Copy link
Member

The diagnostic should probably say something more specific like "cannot pass an array [T] as a vararg T..." or at least "got a [T], expected a T".

@CodaFi
Copy link
Member

CodaFi commented Dec 15, 2017

#13471 gets this to diagnose as "cannot convert value of type '[Base]' to expected argument type 'Base'" but the real solution here would probably involve adding a new ContextualTypePurpose for variadic parameter arguments to diagnose it as a more specific kind of conversion failure.

@swift-ci
Copy link
Collaborator

Comment by Owen Voorhees (JIRA)

Resolved in [[Diagnostics] Improve diagnostic when attempting to pass an Array to a variadic argument|#26207]

@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

4 participants