Skip to content

Bad diagnostic inside closure argument to overloaded func #85981

@AnthonyLatsis

Description

@AnthonyLatsis

Description

No response

Reproduction

extension Sequence {
  @available(swift, deprecated: 4.1)
  func myFlatMap<T>(_: (Element) -> T?) -> [T] {}
  func myFlatMap<T: Sequence>(_: (Element) -> T) -> [T.Element] {}
}
func test(_ array: [String]) -> [String] {
  array.myFlatMap { str in
    if true {
      return [str]
    } else {
      return [str, str.undefined]
    }
  }
}
 184 |   array.myFlatMap { str in
 185 |     if true {
 186 |       return [str]
     |              `- error: cannot convert value of type '[String]' to closure result type 'String'
 187 |     } else {
 188 |       return [str, str.undefined]

Expected behavior

 186 |       return [str]
 187 |     } else {
 188 |       return [str, str.undefined]
     |                        `- error: value of type 'String' has no member 'undefined'
 189 |     }
 190 |   }

Environment

Swift version 6.3-dev (ce082bc)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    closuresFeature: closurescompilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsoverloadingFeature: Overloading symbol namesswift 6.3type checkerArea → compiler: Semantic analysis

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions