diff --git a/Snapshots/Issues/697.swift b/Snapshots/Issues/697.swift index 9444bf1b..8c4d142a 100644 --- a/Snapshots/Issues/697.swift +++ b/Snapshots/Issues/697.swift @@ -391,25 +391,25 @@ private struct _FirestoreKeyedDecodingContainer: KeyedDecodingCont public func nestedContainer(keyedBy _: NestedKey.Type, forKey key: Key) throws -> KeyedDecodingContainer { - decoder.codingPath.append(key) - defer { self.decoder.codingPath.removeLast() } + decoder.codingPath.append(key) + defer { self.decoder.codingPath.removeLast() } - guard let value = self.container[key.stringValue] else { - throw DecodingError.valueNotFound(KeyedDecodingContainer.self, - DecodingError.Context(codingPath: codingPath, - debugDescription: "Cannot get nested keyed container -- no value found for key \"\(key.stringValue)\"")) - } - - guard let dictionary = value as? [String: Any] else { - throw DecodingError - ._typeMismatch(at: codingPath, expectation: [String: Any].self, reality: value) - } - - let container = _FirestoreKeyedDecodingContainer(referencing: decoder, - wrapping: dictionary) - return KeyedDecodingContainer(container) + guard let value = self.container[key.stringValue] else { + throw DecodingError.valueNotFound(KeyedDecodingContainer.self, + DecodingError.Context(codingPath: codingPath, + debugDescription: "Cannot get nested keyed container -- no value found for key \"\(key.stringValue)\"")) } + guard let dictionary = value as? [String: Any] else { + throw DecodingError + ._typeMismatch(at: codingPath, expectation: [String: Any].self, reality: value) + } + + let container = _FirestoreKeyedDecodingContainer(referencing: decoder, + wrapping: dictionary) + return KeyedDecodingContainer(container) + } + public func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer { decoder.codingPath.append(key) defer { self.decoder.codingPath.removeLast() } diff --git a/Sources/ParsingHelpers.swift b/Sources/ParsingHelpers.swift index 15065068..87b3f6ec 100644 --- a/Sources/ParsingHelpers.swift +++ b/Sources/ParsingHelpers.swift @@ -392,7 +392,7 @@ extension Formatter { } } return false - case "func", "subscript", "class", "struct", "protocol", "enum", "extension": + case "func", "subscript", "class", "struct", "protocol", "enum", "extension", "throws": return false default: return true diff --git a/Tests/ParsingHelpersTests.swift b/Tests/ParsingHelpersTests.swift index 9df1ff6c..acd49c3a 100644 --- a/Tests/ParsingHelpersTests.swift +++ b/Tests/ParsingHelpersTests.swift @@ -157,11 +157,31 @@ class ParsingHelpersTests: XCTestCase { XCTAssertFalse(formatter.isStartOfClosure(at: 8)) } + func testThrowingFunctionWithReturnTypeNotTreatedAsClosure() { + let formatter = Formatter(tokenize("func foo() throws -> Bar {}")) + XCTAssertFalse(formatter.isStartOfClosure(at: 12)) + } + + func testThrowingFunctionWithGenericReturnTypeNotTreatedAsClosure() { + let formatter = Formatter(tokenize("func foo() throws -> Bar {}")) + XCTAssertFalse(formatter.isStartOfClosure(at: 18)) + } + func testFunctionAllmanBracesNotTreatedAsClosure() { let formatter = Formatter(tokenize("func foo()\n{\n bar = 5\n}")) XCTAssertFalse(formatter.isStartOfClosure(at: 6)) } + func testFunctionWithWhereClauseBracesNotTreatedAsClosure() { + let formatter = Formatter(tokenize("func foo() where T == Result {}")) + XCTAssertFalse(formatter.isStartOfClosure(at: 26)) + } + + func testThrowingFunctionWithWhereClauseBracesNotTreatedAsClosure() { + let formatter = Formatter(tokenize("func foo() throws where T == Result {}")) + XCTAssertFalse(formatter.isStartOfClosure(at: 28)) + } + func testInitBracesNotTreatedAsClosure() { let formatter = Formatter(tokenize("init() { foo = 5 }")) XCTAssertFalse(formatter.isStartOfClosure(at: 4)) diff --git a/Tests/XCTestManifests.swift b/Tests/XCTestManifests.swift index 6d99f8a3..d5d15c77 100644 --- a/Tests/XCTestManifests.swift +++ b/Tests/XCTestManifests.swift @@ -343,6 +343,7 @@ extension ParsingHelpersTests { ("testFunctionAllmanBracesNotTreatedAsClosure", testFunctionAllmanBracesNotTreatedAsClosure), ("testFunctionBracesNotTreatedAsClosure", testFunctionBracesNotTreatedAsClosure), ("testFunctionInGetterPosition", testFunctionInGetterPosition), + ("testFunctionWithWhereClauseBracesNotTreatedAsClosure", testFunctionWithWhereClauseBracesNotTreatedAsClosure), ("testGenericFunctionNotTreatedAsClosure", testGenericFunctionNotTreatedAsClosure), ("testGenericSubscriptSetGet", testGenericSubscriptSetGet), ("testGetSet", testGetSet), @@ -382,6 +383,9 @@ extension ParsingHelpersTests { ("testSubscriptAllmanBracesNotTreatedAsClosure", testSubscriptAllmanBracesNotTreatedAsClosure), ("testSubscriptBracesNotTreatedAsClosure", testSubscriptBracesNotTreatedAsClosure), ("testThrowingFunctionBracesNotTreatedAsClosure", testThrowingFunctionBracesNotTreatedAsClosure), + ("testThrowingFunctionWithGenericReturnTypeNotTreatedAsClosure", testThrowingFunctionWithGenericReturnTypeNotTreatedAsClosure), + ("testThrowingFunctionWithReturnTypeNotTreatedAsClosure", testThrowingFunctionWithReturnTypeNotTreatedAsClosure), + ("testThrowingFunctionWithWhereClauseBracesNotTreatedAsClosure", testThrowingFunctionWithWhereClauseBracesNotTreatedAsClosure), ("testTupleReturningFunctionBracesNotTreatedAsClosure", testTupleReturningFunctionBracesNotTreatedAsClosure), ("testTypedVarAssignmentBracesTreatedAsClosure", testTypedVarAssignmentBracesTreatedAsClosure), ("testVarAssignmentBracesTreatedAsClosure", testVarAssignmentBracesTreatedAsClosure),