Files
swift-mirror/test/SourceKit/DocSupport/doc_error_domain.swift
Jordan Rose e575d2d5ba [ClangImporter] Error structs from enums are not imported decls.
Enums with the ns_error_domain attribute represent codes for NSError,
which means Swift developers will expect to interact with them in
terms of Error. SE-0112 improved bridging for these enums to generate
a struct with the following form:

    struct MyError: Error {
      @objc enum Code: RawRepresentable {
        case outOfMemory
        case fileNotFound
      }
      var userInfo: [NSObject: AnyObject] { get }
      static var outOfMemory: Code { get }
      static var fileNotFound: Code { get }
    }

where MyError.Code corresponds to the original MyError enum defined in
Objective-C. Until recently, both the enum and the synthesized struct
were marked as having the original enum as their "Clang node", but
that leads to problems: the struct isn't really ObjC-compatible, and
the two decls have the same USR. (The latter had already been worked
around.)

This commit changes the struct to be merely considered a synthesized
"external definition", with no associated Clang node. This meant
auditing everywhere that's looking for a Clang node and seeing which
ones applied to external definitions in general.

There is one regression in quality here: the generated struct is no
longer printed as part of the Swift interface for a header file, since
it's not actually a decl with a corresponding Clang node. The previous
change to AST printing mitigates this a little by at least indicating
that the enum has become a nested "Code" type.
2017-04-24 09:57:41 -07:00

33 lines
1.3 KiB
Swift

// REQUIRES: OS=macosx
// RUN: %sourcekitd-test -req=doc-info -module MyError -- -I %S/Inputs \
// RUN: %mcp_opt -sdk %sdk | %sed_clean > %t.response
// RUN: %FileCheck -input-file=%t.response %s
// CHECK: struct MyError {
// CHECK: enum Code : Int32 {
// CHECK: case errFirst
// CHECK: case errSecond
// CHECK: }
// CHECK: static var errFirst: MyError.Code { get }
// CHECK: static var errSecond: MyError.Code { get }
// CHECK: key.kind: source.lang.swift.decl.struct,
// CHECK-NEXT: key.name: "MyError",
// CHECK-NEXT: key.usr: "s:SC7MyErrorV",
// CHECK-NOT: This is my cool error code.
// CHECK: key.kind: source.lang.swift.decl.enum,
// CHECK-NEXT: key.name: "Code",
// CHECK-NEXT: key.usr: "c:@E@MyErrorCode",
// CHECK-NEXT: This is my cool error code.
// CHECK: key.kind: source.lang.swift.decl.enumelement,
// CHECK-NEXT: key.name: "errFirst",
// CHECK-NEXT: key.usr: "c:@E@MyErrorCode@MyErrFirst",
// CHECK-NEXT: This is first error.
// CHECK: key.kind: source.lang.swift.decl.var.static,
// CHECK-NEXT: key.name: "errFirst",
// CHECK-NEXT: key.usr: "s:SC7MyErrorV8errFirstAB4CodeOvZ",
// CHECK-NEXT: This is first error.