Skip to content

Poor diagnostic for conditional expression result type error #66192

@dabrahams

Description

@dabrahams

Description

Here's a session in the repl that demonstrates

Welcome to Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100).
...
  3> var a = [1]
a: [Int] = 1 value {
  [0] = 1
}
  4> a.append(true ? "yes" : "no")
expression failed to parse:
error: repl.swift:4:17: error: result values in '? :' expression have mismatching types 'String' and 'String'
a.append(true ? "yes" : "no")
                ^~~~~

Obviously the message is nonsense, and the problem is that the conditional expression is fine on its own but has the wrong type for its context.

See the first line of the repl session for version info

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsoperatorsFeature: operatorsswift 5.9ternary operatorFeature → operators: The ternary operatortype checkerArea → compiler: Semantic analysistype inferenceFeature: type inference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions