Uploaded image for project: 'Swift'
  1. Swift
  2. SR-5688

Unhelpful diagnostic when missing a ? in a KeyPath expression

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      Xcode 9.0.0 ß5

      Apple Swift version 4.0 (swiftlang-900.0.59 clang-900.0.34.2)

      Target: x86_64-apple-macosx10.9

      Description

      This code:

      struct A {
          var b: B?
      }
      
      struct B {
          var c: Int
      }
      
      let ab1 = \A.b.c
      dump(ab1)
      

      gives this diagnostic:

      error: MyPlayground.playground:3:11: error: expression type 'WritableKeyPath<A, Int>' is ambiguous without more context
      let ab1 = \A.b.c
      

      That's really unhelpful. The issue here is that a ? is missing. It should be \A.b?.c.

        Attachments

          Activity

            People

            Assignee:
            lucianoalmeida1 Luciano Almeida
            Reporter:
            mdiep Matt Diephouse
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: