diff --git a/include/swift/AST/DiagnosticsCommon.def b/include/swift/AST/DiagnosticsCommon.def index 0047fd8a2c1..65b7728ebd0 100644 --- a/include/swift/AST/DiagnosticsCommon.def +++ b/include/swift/AST/DiagnosticsCommon.def @@ -94,9 +94,11 @@ ERROR(function_type_no_parens,none, "single argument function types require parentheses", ()) // FIXME: Used by swift-api-digester. Don't want to set up a separate diagnostics -// file just for one error. +// file just for two errors. ERROR(sdk_node_unrecognized_key,none, "unrecognized key '%0' in SDK node", (StringRef)) +ERROR(sdk_node_unrecognized_node_kind,none, + "unrecognized SDK node kind '%0'", (StringRef)) //------------------------------------------------------------------------------ // MARK: Circular reference diagnostics diff --git a/include/swift/IDE/APIDigesterData.h b/include/swift/IDE/APIDigesterData.h index 2e0cc6cdce1..9c0d6f07fa8 100644 --- a/include/swift/IDE/APIDigesterData.h +++ b/include/swift/IDE/APIDigesterData.h @@ -33,7 +33,7 @@ enum class SDKNodeKind: uint8_t { #include "DigesterEnums.def" }; -SDKNodeKind parseSDKNodeKind(StringRef Content); +Optional parseSDKNodeKind(StringRef Content); enum class NodeAnnotation: uint8_t{ #define NODE_ANNOTATION(NAME) NAME, diff --git a/lib/IDE/APIDigesterData.cpp b/lib/IDE/APIDigesterData.cpp index 9824a827131..e849672af56 100644 --- a/lib/IDE/APIDigesterData.cpp +++ b/lib/IDE/APIDigesterData.cpp @@ -39,10 +39,11 @@ operator<<(raw_ostream &Out, const NodeAnnotation Value) { llvm_unreachable("Undefined SDK node kind."); } -SDKNodeKind swift::ide::api::parseSDKNodeKind(StringRef Content) { - return llvm::StringSwitch(Content) +Optional swift::ide::api::parseSDKNodeKind(StringRef Content) { + return llvm::StringSwitch>(Content) #define NODE_KIND(NAME, VALUE) .Case(#VALUE, SDKNodeKind::NAME) #include "swift/IDE/DigesterEnums.def" + .Default(None) ; } @@ -326,7 +327,7 @@ serializeDiffItem(llvm::BumpPtrAllocator &Alloc, switch (parseDiffItemKind(DiffItemKind)) { case APIDiffItemKind::ADK_CommonDiffItem: { return new (Alloc.Allocate()) - CommonDiffItem(parseSDKNodeKind(NodeKind), + CommonDiffItem(*parseSDKNodeKind(NodeKind), parseSDKNodeAnnotation(NodeAnnotation), ChildIndex, LeftUsr, RightUsr, LeftComment, RightComment, ModuleName); } diff --git a/test/api-digester/diagnostics.json b/test/api-digester/diagnostics.json index 2c1a9e1223b..81ef51ea20e 100644 --- a/test/api-digester/diagnostics.json +++ b/test/api-digester/diagnostics.json @@ -2,6 +2,8 @@ "kind": "Root", "name": "TopLevel", "printedName": "TopLevel", - "children": [], - "badKey": ["foo", "bar", "baz"] + "badKey": ["foo", "bar", "baz"], + "children": [ + { "kind": "Zyzyx" } + ] } diff --git a/test/api-digester/diagnostics.swift b/test/api-digester/diagnostics.swift index c8b60f138fc..2bfaede6607 100644 --- a/test/api-digester/diagnostics.swift +++ b/test/api-digester/diagnostics.swift @@ -1,7 +1,8 @@ // REQUIRES: OS=macosx // RUN: not %api-digester -deserialize-sdk -input-paths %S/diagnostics.json -o - 2>&1 | %FileCheck %s -// CHECK: diagnostics.json:6:3: error: unrecognized key 'badKey' in SDK node +// CHECK: diagnostics.json:5:3: error: unrecognized key 'badKey' in SDK node +// CHECK: diagnostics.json:7:15: error: unrecognized SDK node kind 'Zyzyx' // Make sure we don't try to output a result: // CHECK-NOT: "kind": "Root", diff --git a/tools/swift-api-digester/swift-api-digester.cpp b/tools/swift-api-digester/swift-api-digester.cpp index 27361d0e123..61b6993038b 100644 --- a/tools/swift-api-digester/swift-api-digester.cpp +++ b/tools/swift-api-digester/swift-api-digester.cpp @@ -1057,7 +1057,14 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx, if (auto keyKind = parseKeyKind(keyString)) { switch(*keyKind) { case KeyKind::KK_kind: - Kind = parseSDKNodeKind(GetScalarString(Pair.getValue())); + if (auto parsedKind = parseSDKNodeKind(GetScalarString(Pair.getValue()))) { + Kind = *parsedKind; + } else { + auto range = convertRange(Pair.getValue()->getSourceRange()); + Ctx.getDiags().diagnose(range.Start, diag::sdk_node_unrecognized_node_kind, + GetScalarString(Pair.getValue())) + .highlight(range); + } break; case KeyKind::KK_name: Info.Name = GetScalarString(Pair.getValue());