From ac214e6760f399821a878a2b29157a8a4a07f58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 29 Jan 2023 18:15:34 +0100 Subject: [PATCH] SE-0345: if let shorthand for shadowing an existing optional variable --- Documentation/GRDB5MigrationGuide.md | 2 +- .../Associations.playground/Contents.swift | 4 ++-- GRDB/Core/Configuration.swift | 2 +- GRDB/Core/Database+Schema.swift | 8 ++++---- GRDB/Core/Database+Statements.swift | 4 ++-- GRDB/Core/Database.swift | 12 ++++++------ GRDB/Core/DatabaseError.swift | 16 ++++++++-------- GRDB/Core/DatabaseRegion.swift | 4 ++-- GRDB/Core/DatabaseValueConvertible.swift | 2 +- GRDB/Core/Statement.swift | 6 +++--- GRDB/Core/StatementAuthorizer.swift | 6 +++--- GRDB/Core/StatementColumnConvertible.swift | 2 +- GRDB/Core/TransactionObserver.swift | 2 +- GRDB/FTS/FTS4.swift | 2 +- GRDB/FTS/FTS5.swift | 4 ++-- GRDB/FTS/FTS5CustomTokenizer.swift | 2 +- GRDB/FTS/FTS5Tokenizer.swift | 2 +- GRDB/FTS/FTS5TokenizerDescriptor.swift | 2 +- .../Association/BelongsToAssociation.swift | 2 +- .../Request/Association/HasManyAssociation.swift | 2 +- .../Request/Association/HasOneAssociation.swift | 2 +- .../Request/CommonTableExpression.swift | 2 +- GRDB/QueryInterface/SQL/SQLExpression.swift | 2 +- .../SQL/SQLForeignKeyRequest.swift | 8 ++++---- GRDB/QueryInterface/SQL/SQLOperators.swift | 2 +- GRDB/QueryInterface/SQL/SQLRelation.swift | 2 +- GRDB/QueryInterface/SQL/Table.swift | 4 ++-- .../SQLGeneration/SQLGenerationContext.swift | 6 +++--- .../SQLGeneration/SQLQueryGenerator.swift | 4 ++-- .../SQLInterpolation+QueryInterface.swift | 4 ++-- GRDB/QueryInterface/Schema/TableDefinition.swift | 10 +++++----- .../Schema/VirtualTableModule.swift | 2 +- .../QueryInterface/TableRecord+Association.swift | 4 ++-- GRDB/Record/EncodableRecord+Encodable.swift | 2 +- GRDB/Record/FetchableRecord+Decodable.swift | 6 +++--- .../Record/MutablePersistableRecord+Upsert.swift | 2 +- GRDB/Record/Record.swift | 2 +- GRDB/Utils/Utils.swift | 2 +- .../Observers/ValueConcurrentObserver.swift | 4 ++-- .../Observers/ValueWriteOnlyObserver.swift | 2 +- .../Reducers/RemoveDuplicates.swift | 2 +- GRDB/ValueObservation/ValueObservation.swift | 2 +- .../PublisherExpectations/Recording.swift | 2 +- Tests/CombineExpectations/Recorder.swift | 2 +- Tests/GRDBTests/DatabaseConfigurationTests.swift | 2 +- .../DatabasePoolReleaseMemoryTests.swift | 4 ++-- .../DatabaseQueueConcurrencyTests.swift | 6 +++--- .../DatabaseQueueReleaseMemoryTests.swift | 4 ++-- Tests/GRDBTests/FoundationNSUUIDTests.swift | 2 +- Tests/GRDBTests/FoundationUUIDTests.swift | 2 +- Tests/GRDBTests/RowAdapterTests.swift | 4 ++-- .../TransactionObserverSavepointsTests.swift | 8 ++++---- Tests/GRDBTests/TransactionObserverTests.swift | 12 ++++++------ Tests/GRDBTests/ValueObservationRecorder.swift | 10 +++++----- 54 files changed, 110 insertions(+), 110 deletions(-) diff --git a/Documentation/GRDB5MigrationGuide.md b/Documentation/GRDB5MigrationGuide.md index 8ff58693f..eca1c7ca7 100644 --- a/Documentation/GRDB5MigrationGuide.md +++ b/Documentation/GRDB5MigrationGuide.md @@ -197,7 +197,7 @@ The changes can quite impact your application. We'll describe them below, as wel scheduling: .immediate, onError: { error in ... }, onChange: { [weak self] (players: [Player]) in - guard let self = self else { return } + guard let self else { return } self.updateView(players) }) // <- Here the view has already been updated. diff --git a/Documentation/Playgrounds/Associations.playground/Contents.swift b/Documentation/Playgrounds/Associations.playground/Contents.swift index be4015f98..1fd67547b 100644 --- a/Documentation/Playgrounds/Associations.playground/Contents.swift +++ b/Documentation/Playgrounds/Associations.playground/Contents.swift @@ -103,7 +103,7 @@ let authorInfo: AuthorInfo? = try dbQueue.read { db in let books = try author.books.fetchAll(db) return AuthorInfo(author: author, books: books) } -if let authorInfo = authorInfo { +if let authorInfo { print("\(authorInfo.author.name) has written:") for book in authorInfo.books { print("- \(book.title)") @@ -126,7 +126,7 @@ let bookInfo: BookInfo? = try dbQueue.read { db in .including(required: Book.author) return try BookInfo.fetchOne(db, request) } -if let bookInfo = bookInfo { +if let bookInfo { print("\(bookInfo.book.title) was written by \(bookInfo.author.name)") } diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index 2316c2cb1..5d453fa72 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -406,7 +406,7 @@ public struct Configuration { /// Creates a DispatchQueue which has the quality of service and target /// queue of read accesses. func makeReaderDispatchQueue(label: String) -> DispatchQueue { - if let targetQueue = targetQueue { + if let targetQueue { return DispatchQueue(label: label, target: targetQueue) } else { return DispatchQueue(label: label, qos: qos) diff --git a/GRDB/Core/Database+Schema.swift b/GRDB/Core/Database+Schema.swift index d00c31446..25fbe9531 100644 --- a/GRDB/Core/Database+Schema.swift +++ b/GRDB/Core/Database+Schema.swift @@ -1032,7 +1032,7 @@ public struct ForeignKeyViolation { }) var description: String - if let foreignKey = foreignKey { + if let foreignKey { description = """ FOREIGN KEY constraint violation - \ from \(originTable)(\(foreignKey.originColumns.joined(separator: ", "))) \ @@ -1042,9 +1042,9 @@ public struct ForeignKeyViolation { description = "FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable)" } - if let originRow = originRow { + if let originRow { description += ", in \(String(describing: originRow))" - } else if let originRowID = originRowID { + } else if let originRowID { description += ", in rowid \(originRowID)" } @@ -1084,7 +1084,7 @@ extension ForeignKeyViolation: CustomStringConvertible { /// /// See also ``failureDescription(_:)``. public var description: String { - if let originRowID = originRowID { + if let originRowID { return """ FOREIGN KEY constraint violation - from \(originTable) to \(destinationTable), \ in rowid \(originRowID) diff --git a/GRDB/Core/Database+Statements.swift b/GRDB/Core/Database+Statements.swift index fef0ee236..77703eccd 100644 --- a/GRDB/Core/Database+Statements.swift +++ b/GRDB/Core/Database+Statements.swift @@ -406,8 +406,8 @@ extension SQLStatementCursor: Cursor { /// Check that all arguments were consumed: it is a programmer error to /// provide arguments that do not match the statements. private func checkArgumentsAreEmpty() throws { - if let arguments = arguments, - let initialArgumentCount = initialArgumentCount, + if let arguments, + let initialArgumentCount, arguments.values.isEmpty == false { throw DatabaseError( diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index fb0e129c2..dd07cfb9a 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -335,10 +335,10 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib _ = sqlite3_close(sqliteConnection) // ignore result code throw DatabaseError(resultCode: code) } - if let sqliteConnection = sqliteConnection { - return sqliteConnection + guard let sqliteConnection else { + throw DatabaseError(resultCode: .SQLITE_INTERNAL) // WTF SQLite? } - throw DatabaseError(resultCode: .SQLITE_INTERNAL) // WTF SQLite? + return sqliteConnection } // MARK: - Database Setup @@ -1163,7 +1163,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib } } - if let firstError = firstError { + if let firstError { throw firstError } } @@ -1312,7 +1312,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib } } - if let firstError = firstError { + if let firstError { throw firstError } } @@ -1886,7 +1886,7 @@ extension Database { fatalError("Unavailable statement SQL") case let .trace_v2(sqliteStatement, unexpandedSQL, _, _): - if let unexpandedSQL = unexpandedSQL { + if let unexpandedSQL { return String(cString: unexpandedSQL).trimmedSQLStatement } else { return String(cString: sqlite3_sql(sqliteStatement)).trimmedSQLStatement diff --git a/GRDB/Core/DatabaseError.swift b/GRDB/Core/DatabaseError.swift index 7fdc9d1ab..a703f9c2a 100644 --- a/GRDB/Core/DatabaseError.swift +++ b/GRDB/Core/DatabaseError.swift @@ -198,7 +198,7 @@ extension ResultCode: CustomStringConvertible { } public var description: String { - if let errorString = errorString { + if let errorString { return "\(rawValue) (\(errorString))" } else { return "\(rawValue)" @@ -543,13 +543,13 @@ extension DatabaseError: CustomStringConvertible { /// without notice: don't have your application rely on any specific format. public var description: String { var description = "SQLite error \(resultCode.rawValue)" - if let message = message { + if let message { description += ": \(message)" } - if let sql = sql { + if let sql { description += " - while executing `\(sql)`" } - if publicStatementArguments, let arguments = arguments, !arguments.isEmpty { + if publicStatementArguments, let arguments, !arguments.isEmpty { description += " with arguments \(arguments)" } return description @@ -571,13 +571,13 @@ extension DatabaseError: CustomStringConvertible { /// property with care. public var expandedDescription: String { var description = "SQLite error \(resultCode.rawValue)" - if let message = message { + if let message { description += ": \(message)" } - if let sql = sql { + if let sql { description += " - while executing `\(sql)`" } - if let arguments = arguments, !arguments.isEmpty { + if let arguments, !arguments.isEmpty { description += " with arguments \(arguments)" } return description @@ -598,7 +598,7 @@ extension DatabaseError: CustomNSError { /// Part of the `CustomNSError` conformance. public var errorUserInfo: [String: Any] { var userInfo = [NSLocalizedDescriptionKey: description] - if let message = message { + if let message { userInfo[NSLocalizedFailureReasonErrorKey] = message } return userInfo diff --git a/GRDB/Core/DatabaseRegion.swift b/GRDB/Core/DatabaseRegion.swift index 384a9e414..232cd472d 100644 --- a/GRDB/Core/DatabaseRegion.swift +++ b/GRDB/Core/DatabaseRegion.swift @@ -287,8 +287,8 @@ private struct TableRegion: Equatable { var rowIds: Set? // nil means "all rowids" var isEmpty: Bool { - if let columns = columns, columns.isEmpty { return true } - if let rowIds = rowIds, rowIds.isEmpty { return true } + if let columns, columns.isEmpty { return true } + if let rowIds, rowIds.isEmpty { return true } return false } diff --git a/GRDB/Core/DatabaseValueConvertible.swift b/GRDB/Core/DatabaseValueConvertible.swift index 44afac439..ce5017a42 100644 --- a/GRDB/Core/DatabaseValueConvertible.swift +++ b/GRDB/Core/DatabaseValueConvertible.swift @@ -159,7 +159,7 @@ public final class DatabaseValueCursor: Databas init(statement: Statement, arguments: StatementArguments? = nil, adapter: (any RowAdapter)? = nil) throws { self._statement = statement - if let adapter = adapter { + if let adapter { // adapter may redefine the index of the leftmost column columnIndex = try CInt(adapter.baseColumnIndex(atIndex: 0, layout: statement)) } else { diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index 706d03b87..5f2334bb2 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -294,7 +294,7 @@ public final class Statement { var valuesIterator = arguments.values.makeIterator() for (index, argumentName) in zip(CInt(1)..., sqliteArgumentNames) { - if let argumentName = argumentName, let value = arguments.namedValues[argumentName] { + if let argumentName, let value = arguments.namedValues[argumentName] { bind(value, at: index) } else if let value = valuesIterator.next() { bind(value, at: index) @@ -372,7 +372,7 @@ public final class Statement { func reset(withArguments arguments: StatementArguments?) throws { // Force arguments validity: it is a programmer error to provide // arguments that do not match the statement. - if let arguments = arguments { + if let arguments { try setArguments(arguments) } else if argumentsNeedValidation { try reset() @@ -1122,7 +1122,7 @@ public struct StatementArguments: Hashable { { let initialValuesCount = values.count let bindings = try statement.sqliteArgumentNames.map { argumentName -> DatabaseValue in - if let argumentName = argumentName { + if let argumentName { if let dbValue = namedValues[argumentName] { return dbValue } else if values.isEmpty { diff --git a/GRDB/Core/StatementAuthorizer.swift b/GRDB/Core/StatementAuthorizer.swift index e77d823eb..5fe6f9dbe 100644 --- a/GRDB/Core/StatementAuthorizer.swift +++ b/GRDB/Core/StatementAuthorizer.swift @@ -107,7 +107,7 @@ final class StatementAuthorizer { case SQLITE_DELETE: if isDropStatement { return SQLITE_OK } - guard let cString1 = cString1 else { return SQLITE_OK } + guard let cString1 else { return SQLITE_OK } // Deletions from sqlite_master and sqlite_temp_master are not like // other deletions: `sqlite3_update_hook` does not notify them, and @@ -137,7 +137,7 @@ final class StatementAuthorizer { return SQLITE_OK case SQLITE_TRANSACTION: - guard let cString1 = cString1 else { return SQLITE_OK } + guard let cString1 else { return SQLITE_OK } if strcmp(cString1, "BEGIN") == 0 { transactionEffect = .beginTransaction } else if strcmp(cString1, "COMMIT") == 0 { @@ -148,7 +148,7 @@ final class StatementAuthorizer { return SQLITE_OK case SQLITE_SAVEPOINT: - guard let cString1 = cString1 else { return SQLITE_OK } + guard let cString1 else { return SQLITE_OK } guard let name = cString2.map(String.init) else { return SQLITE_OK } if strcmp(cString1, "BEGIN") == 0 { transactionEffect = .beginSavepoint(name) diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index 27995317e..87efd16f1 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -215,7 +215,7 @@ where Value: DatabaseValueConvertible & StatementColumnConvertible init(statement: Statement, arguments: StatementArguments? = nil, adapter: (any RowAdapter)? = nil) throws { self._statement = statement - if let adapter = adapter { + if let adapter { // adapter may redefine the index of the leftmost column columnIndex = try CInt(adapter.baseColumnIndex(atIndex: 0, layout: statement)) } else { diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index 00fca82e7..c0730130e 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -1699,7 +1699,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl { { var value: SQLiteValue? = nil guard sqlite_func(connection, column, &value) == SQLITE_OK else { return nil } - if let value = value { + if let value { return DatabaseValue(sqliteValue: value) } return nil diff --git a/GRDB/FTS/FTS4.swift b/GRDB/FTS/FTS4.swift index ab5cbefef..6d243c296 100644 --- a/GRDB/FTS/FTS4.swift +++ b/GRDB/FTS/FTS4.swift @@ -62,7 +62,7 @@ extension FTS4: VirtualTableModule { switch definition.contentMode { case .raw(let content): - if let content = content { + if let content { arguments.append("content=\"\(content)\"") } case .synchronized(let contentTable): diff --git a/GRDB/FTS/FTS5.swift b/GRDB/FTS/FTS5.swift index 3b10cfca0..148a681a8 100644 --- a/GRDB/FTS/FTS5.swift +++ b/GRDB/FTS/FTS5.swift @@ -114,11 +114,11 @@ public struct FTS5: VirtualTableModule { switch definition.contentMode { case let .raw(content, contentRowID): - if let content = content { + if let content { let quotedContent = try content.sqlExpression.quotedSQL(db) arguments.append("content=\(quotedContent)") } - if let contentRowID = contentRowID { + if let contentRowID { let quotedContentRowID = try contentRowID.sqlExpression.quotedSQL(db) arguments.append("content_rowid=\(quotedContentRowID)") } diff --git a/GRDB/FTS/FTS5CustomTokenizer.swift b/GRDB/FTS/FTS5CustomTokenizer.swift index 313d2e850..145c8bc8c 100644 --- a/GRDB/FTS/FTS5CustomTokenizer.swift +++ b/GRDB/FTS/FTS5CustomTokenizer.swift @@ -108,7 +108,7 @@ extension Database { } let constructor = Unmanaged.fromOpaque(constructorPointer).takeUnretainedValue() var arguments: [String] = [] - if let azArg = azArg { + if let azArg { for i in 0.. public static func porter(wrapping base: FTS5TokenizerDescriptor? = nil) -> FTS5TokenizerDescriptor { - if let base = base { + if let base { return FTS5TokenizerDescriptor(components: ["porter"] + base.components) } else { return FTS5TokenizerDescriptor(components: ["porter"]) diff --git a/GRDB/QueryInterface/Request/Association/BelongsToAssociation.swift b/GRDB/QueryInterface/Request/Association/BelongsToAssociation.swift index ea04513d6..205414e8c 100644 --- a/GRDB/QueryInterface/Request/Association/BelongsToAssociation.swift +++ b/GRDB/QueryInterface/Request/Association/BelongsToAssociation.swift @@ -77,7 +77,7 @@ public struct BelongsToAssociation { originIsLeft: true) let associationKey: SQLAssociationKey - if let key = key { + if let key { associationKey = .fixedSingular(key) } else { associationKey = .inflected(destinationTable) diff --git a/GRDB/QueryInterface/Request/Association/HasManyAssociation.swift b/GRDB/QueryInterface/Request/Association/HasManyAssociation.swift index 2b3973005..cce49cdc2 100644 --- a/GRDB/QueryInterface/Request/Association/HasManyAssociation.swift +++ b/GRDB/QueryInterface/Request/Association/HasManyAssociation.swift @@ -77,7 +77,7 @@ public struct HasManyAssociation { originIsLeft: false) let associationKey: SQLAssociationKey - if let key = key { + if let key { associationKey = .fixedPlural(key) } else { associationKey = .inflected(destinationTable) diff --git a/GRDB/QueryInterface/Request/Association/HasOneAssociation.swift b/GRDB/QueryInterface/Request/Association/HasOneAssociation.swift index 36f9e7708..e0ba88751 100644 --- a/GRDB/QueryInterface/Request/Association/HasOneAssociation.swift +++ b/GRDB/QueryInterface/Request/Association/HasOneAssociation.swift @@ -80,7 +80,7 @@ public struct HasOneAssociation { originIsLeft: false) let associationKey: SQLAssociationKey - if let key = key { + if let key { associationKey = .fixedSingular(key) } else { associationKey = .inflected(destinationTable) diff --git a/GRDB/QueryInterface/Request/CommonTableExpression.swift b/GRDB/QueryInterface/Request/CommonTableExpression.swift index 813677ebe..17d192fb2 100644 --- a/GRDB/QueryInterface/Request/CommonTableExpression.swift +++ b/GRDB/QueryInterface/Request/CommonTableExpression.swift @@ -334,7 +334,7 @@ struct SQLCTE { /// The number of columns in the common table expression. func columnCount(_ db: Database) throws -> Int { - if let columns = columns { + if let columns { // No need to hit the database return columns.count } diff --git a/GRDB/QueryInterface/SQL/SQLExpression.swift b/GRDB/QueryInterface/SQL/SQLExpression.swift index 44e47d576..b3cba98b9 100644 --- a/GRDB/QueryInterface/SQL/SQLExpression.swift +++ b/GRDB/QueryInterface/SQL/SQLExpression.swift @@ -979,7 +979,7 @@ extension SQLExpression { \(op.sql) \ \(rhs.sql(context, wrappedInParenthesis: true)) """ - if let escape = escape { + if let escape { resultSQL += try " ESCAPE \(escape.sql(context, wrappedInParenthesis: true))" } if wrappedInParenthesis { diff --git a/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift b/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift index 75d4af2cd..1a74399c5 100644 --- a/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift +++ b/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift @@ -22,7 +22,7 @@ struct SQLForeignKeyRequest { /// The (origin, destination) column pairs that join a left table to a right table. func fetchForeignKeyMapping(_ db: Database) throws -> ForeignKeyMapping { - if let originColumns = originColumns, let destinationColumns = destinationColumns { + if let originColumns, let destinationColumns = destinationColumns { // Total information: no need to query the database schema. GRDBPrecondition(originColumns.count == destinationColumns.count, "Number of columns don't match") let mapping = zip(originColumns, destinationColumns).map { @@ -36,14 +36,14 @@ struct SQLForeignKeyRequest { if destinationTable.lowercased() != foreignKey.destinationTable.lowercased() { return false } - if let originColumns = originColumns { + if let originColumns { let originColumns = Set(originColumns.lazy.map { $0.lowercased() }) let foreignKeyColumns = Set(foreignKey.mapping.lazy.map { $0.origin.lowercased() }) if originColumns != foreignKeyColumns { return false } } - if let destinationColumns = destinationColumns { + if let destinationColumns { // TODO: test let destinationColumns = Set(destinationColumns.lazy.map { $0.lowercased() }) let foreignKeyColumns = Set(foreignKey.mapping.lazy.map { $0.destination.lowercased() }) @@ -66,7 +66,7 @@ struct SQLForeignKeyRequest { } // No matching foreign key found: use the destination primary key - if let originColumns = originColumns { + if let originColumns { let destinationColumns = try db.primaryKey(destinationTable).columns if originColumns.count == destinationColumns.count { let mapping = zip(originColumns, destinationColumns).map { diff --git a/GRDB/QueryInterface/SQL/SQLOperators.swift b/GRDB/QueryInterface/SQL/SQLOperators.swift index bf7759f99..6277924f0 100644 --- a/GRDB/QueryInterface/SQL/SQLOperators.swift +++ b/GRDB/QueryInterface/SQL/SQLOperators.swift @@ -126,7 +126,7 @@ extension SQLSpecificExpressible { /// The `IS` SQL operator. public static func === (lhs: (any SQLExpressible)?, rhs: Self) -> SQLExpression { - if let lhs = lhs { + if let lhs { return .compare(.is, lhs.sqlExpression, rhs.sqlExpression) } else { return .compare(.is, rhs.sqlExpression, .null) diff --git a/GRDB/QueryInterface/SQL/SQLRelation.swift b/GRDB/QueryInterface/SQL/SQLRelation.swift index 4bd764e29..c94c43ed6 100644 --- a/GRDB/QueryInterface/SQL/SQLRelation.swift +++ b/GRDB/QueryInterface/SQL/SQLRelation.swift @@ -635,7 +635,7 @@ struct SQLLimit { let offset: Int? var sql: String { - if let offset = offset { + if let offset { return "\(limit) OFFSET \(offset)" } else { return "\(limit)" diff --git a/GRDB/QueryInterface/SQL/Table.swift b/GRDB/QueryInterface/SQL/Table.swift index f73811649..3b5486a7f 100644 --- a/GRDB/QueryInterface/SQL/Table.swift +++ b/GRDB/QueryInterface/SQL/Table.swift @@ -1346,7 +1346,7 @@ extension Table { { let association = HasManyThroughAssociation(through: pivot, using: target) - if let key = key { + if let key { return association.forKey(key) } else { return association @@ -1378,7 +1378,7 @@ extension Table { { let association = HasOneThroughAssociation(through: pivot, using: target) - if let key = key { + if let key { return association.forKey(key) } else { return association diff --git a/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift b/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift index 80131277b..7f7724ccd 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift @@ -324,7 +324,7 @@ public class TableAlias { switch impl { case let .undefined(userName): - if let userName = userName { + if let userName { // rename assert(base.userName == nil || base.userName == userName) base.setUserName(userName) @@ -332,7 +332,7 @@ public class TableAlias { self.impl = .proxy(base) case let .table(tableName: tableName, userName: userName): assert(tableName == base.tableName) - if let userName = userName { + if let userName { // rename assert(base.userName == nil || base.userName == userName) base.setUserName(userName) @@ -358,7 +358,7 @@ public class TableAlias { // can't merge return nil } - if let userName = userName, let otherUserName = otherUserName, userName != otherUserName { + if let userName, let otherUserName, userName != otherUserName { // can't merge return nil } diff --git a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift index 9d393571b..5c39d13e3 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift @@ -47,7 +47,7 @@ struct SQLQueryGenerator: Refinable { } let filter = try relation.filterPromise?.resolve(context.db) - if let filter = filter { + if let filter { sql += " WHERE " sql += try filter.sql(context) } @@ -83,7 +83,7 @@ struct SQLQueryGenerator: Refinable { limit = SQLLimit(limit: 1, offset: limit?.offset) } - if let limit = limit { + if let limit { sql += " LIMIT " sql += limit.sql } diff --git a/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift b/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift index 0cfca9a21..d108d46b3 100644 --- a/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift +++ b/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift @@ -74,7 +74,7 @@ extension SQLInterpolation { /// """ @_disfavoredOverload public mutating func appendInterpolation(_ selection: (any SQLSelectable)?) { - if let selection = selection { + if let selection { elements.append(.selection(selection.sqlSelection)) } else { appendLiteral("NULL") @@ -127,7 +127,7 @@ extension SQLInterpolation { /// """ @_disfavoredOverload public mutating func appendInterpolation(_ expressible: (any SQLExpressible)?) { - if let expressible = expressible { + if let expressible { elements.append(.expression(expressible.sqlExpression)) } else { appendLiteral("NULL") diff --git a/GRDB/QueryInterface/Schema/TableDefinition.swift b/GRDB/QueryInterface/Schema/TableDefinition.swift index 3b5b95919..20019c986 100644 --- a/GRDB/QueryInterface/Schema/TableDefinition.swift +++ b/GRDB/QueryInterface/Schema/TableDefinition.swift @@ -1909,13 +1909,13 @@ public final class ColumnDefinition { fileprivate func sql(_ db: Database, tableName: String, primaryKeyColumns: [String]?) throws -> String { var chunks: [String] = [] chunks.append(name.quotedDatabaseIdentifier) - if let type = type { + if let type { chunks.append(type.rawValue) } if let (conflictResolution, autoincrement) = primaryKey { chunks.append("PRIMARY KEY") - if let conflictResolution = conflictResolution { + if let conflictResolution { chunks.append("ON CONFLICT") chunks.append(conflictResolution.rawValue) } @@ -1953,11 +1953,11 @@ public final class ColumnDefinition { try chunks.append("CHECK (\(checkConstraint.quotedSQL(db)))") } - if let defaultExpression = defaultExpression { + if let defaultExpression { try chunks.append("DEFAULT \(defaultExpression.quotedSQL(db))") } - if let collationName = collationName { + if let collationName { chunks.append("COLLATE") chunks.append(collationName) } @@ -2064,7 +2064,7 @@ private struct IndexDefinition { \(columns.map(\.quotedDatabaseIdentifier).joined(separator: ", "))\ ) """) - if let condition = condition { + if let condition { try chunks.append("WHERE \(condition.quotedSQL(db))") } return chunks.joined(separator: " ") diff --git a/GRDB/QueryInterface/Schema/VirtualTableModule.swift b/GRDB/QueryInterface/Schema/VirtualTableModule.swift index 9aba55308..07bdf7bdd 100644 --- a/GRDB/QueryInterface/Schema/VirtualTableModule.swift +++ b/GRDB/QueryInterface/Schema/VirtualTableModule.swift @@ -130,7 +130,7 @@ extension Database { // Define virtual table let configuration = VirtualTableConfiguration(ifNotExists: ifNotExists) let definition = module.makeTableDefinition(configuration: configuration) - if let body = body { + if let body { try body(definition) } diff --git a/GRDB/QueryInterface/TableRecord+Association.swift b/GRDB/QueryInterface/TableRecord+Association.swift index 766d06ffa..e86a54814 100644 --- a/GRDB/QueryInterface/TableRecord+Association.swift +++ b/GRDB/QueryInterface/TableRecord+Association.swift @@ -443,7 +443,7 @@ extension TableRecord { { let association = HasManyThroughAssociation(through: pivot, using: target) - if let key = key { + if let key { return association.forKey(key) } else { return association @@ -529,7 +529,7 @@ extension TableRecord { { let association = HasOneThroughAssociation(through: pivot, using: target) - if let key = key { + if let key { return association.forKey(key) } else { return association diff --git a/GRDB/Record/EncodableRecord+Encodable.swift b/GRDB/Record/EncodableRecord+Encodable.swift index 2d6e5dba4..0782dc6b3 100644 --- a/GRDB/Record/EncodableRecord+Encodable.swift +++ b/GRDB/Record/EncodableRecord+Encodable.swift @@ -94,7 +94,7 @@ private class RecordEncoder: Encoder { // swiftlint:enable comma func encodeIfPresent(_ value: T?, forKey key: Key) throws where T: Encodable { - if let value = value { + if let value { try recordEncoder.encode(value, forKey: key) } else { recordEncoder.persist(nil, forKey: key) diff --git a/GRDB/Record/FetchableRecord+Decodable.swift b/GRDB/Record/FetchableRecord+Decodable.swift index d74a49c05..c561ccbdf 100644 --- a/GRDB/Record/FetchableRecord+Decodable.swift +++ b/GRDB/Record/FetchableRecord+Decodable.swift @@ -98,7 +98,7 @@ private struct _RowDecoder: Decoder { func contains(_ key: Key) -> Bool { let row = decoder.row - if let _columnForKey = _columnForKey { + if let _columnForKey { if let column = _columnForKey[key.stringValue] { assert(row.hasColumn(column)) return true @@ -299,7 +299,7 @@ private struct _RowDecoder: Decoder { // "book", which is not the name of a column, and not the name of a // scope) has to be decoded right from the base row. But this can // happen only once. - if let decodedRootKey = decodedRootKey { + if let decodedRootKey { let keys = [decodedRootKey.stringValue, key.stringValue].sorted() throw DecodingError.keyNotFound(key, DecodingError.Context( codingPath: codingPath, @@ -369,7 +369,7 @@ private struct _RowDecoder: Decoder { } catch is JSONRequiredError { // Decode from JSON return try row.withUnsafeData(atIndex: index) { data in - guard let data = data else { + guard let data else { throw DecodingError.valueNotFound(Data.self, DecodingError.Context( codingPath: codingPath + [key], debugDescription: "Missing Data")) diff --git a/GRDB/Record/MutablePersistableRecord+Upsert.swift b/GRDB/Record/MutablePersistableRecord+Upsert.swift index e38d670df..9cca9cd20 100644 --- a/GRDB/Record/MutablePersistableRecord+Upsert.swift +++ b/GRDB/Record/MutablePersistableRecord+Upsert.swift @@ -442,7 +442,7 @@ extension MutablePersistableRecord { // to false in its `aroundInsert` callback. var persistenceContainer = dao.persistenceContainer let rowIDColumn = dao.primaryKey.rowIDColumn - if let rowIDColumn = rowIDColumn { + if let rowIDColumn { persistenceContainer[caseInsensitive: rowIDColumn] = rowid } diff --git a/GRDB/Record/Record.swift b/GRDB/Record/Record.swift index 86902314f..02097265c 100644 --- a/GRDB/Record/Record.swift +++ b/GRDB/Record/Record.swift @@ -203,7 +203,7 @@ open class Record { // Loop until we find a change, or exhaust columns: while let (column, newValue) = newValueIterator.next() { let newDbValue = newValue?.databaseValue ?? .null - guard let oldRow = oldRow, let oldDbValue: DatabaseValue = oldRow[column] else { + guard let oldRow, let oldDbValue: DatabaseValue = oldRow[column] else { return (column, nil) } if newDbValue != oldDbValue { diff --git a/GRDB/Utils/Utils.swift b/GRDB/Utils/Utils.swift index 49ef225c5..63dec625e 100644 --- a/GRDB/Utils/Utils.swift +++ b/GRDB/Utils/Utils.swift @@ -112,7 +112,7 @@ func throwingFirstError(execute: () throws -> T, finally: () throws -> Void) firstError = error } } - if let firstError = firstError { + if let firstError { throw firstError } return result! diff --git a/GRDB/ValueObservation/Observers/ValueConcurrentObserver.swift b/GRDB/ValueObservation/Observers/ValueConcurrentObserver.swift index b4e94fc3a..9508ee4a8 100644 --- a/GRDB/ValueObservation/Observers/ValueConcurrentObserver.swift +++ b/GRDB/ValueObservation/Observers/ValueConcurrentObserver.swift @@ -438,7 +438,7 @@ extension ValueConcurrentObserver { let value = try self.reducer._value(fetchedValue) // Notify - if let value = value { + if let value { self.scheduler.schedule { let onChange = self.lock.synchronized { self.notificationCallbacks?.onChange } guard let onChange else { return /* Cancelled */ } @@ -566,7 +566,7 @@ extension ValueConcurrentObserver: TransactionObserver { let value = try self.reducer._value(fetchedValue) // Notify value - if let value = value { + if let value { self.scheduler.schedule { let onChange = self.lock.synchronized { self.notificationCallbacks?.onChange } guard let onChange else { return /* Cancelled */ } diff --git a/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift b/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift index 404e73de5..e73e9a394 100644 --- a/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift +++ b/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift @@ -403,7 +403,7 @@ extension ValueWriteOnlyObserver: TransactionObserver { let value = try self.reducer._value(fetchedValue) // Notify value - if let value = value { + if let value { self.scheduler.schedule { let onChange = self.lock.synchronized { self.notificationCallbacks?.onChange } guard let onChange else { return /* Cancelled */ } diff --git a/GRDB/ValueObservation/Reducers/RemoveDuplicates.swift b/GRDB/ValueObservation/Reducers/RemoveDuplicates.swift index df1eb0ab2..6d2e64e53 100644 --- a/GRDB/ValueObservation/Reducers/RemoveDuplicates.swift +++ b/GRDB/ValueObservation/Reducers/RemoveDuplicates.swift @@ -81,7 +81,7 @@ extension ValueReducers { guard let value = try base._value(fetched) else { return nil } - if let previousValue = previousValue, predicate(previousValue, value) { + if let previousValue, predicate(previousValue, value) { // Don't notify consecutive identical values return nil } diff --git a/GRDB/ValueObservation/ValueObservation.swift b/GRDB/ValueObservation/ValueObservation.swift index a887ac2e9..9ad5e29a4 100644 --- a/GRDB/ValueObservation/ValueObservation.swift +++ b/GRDB/ValueObservation/ValueObservation.swift @@ -704,7 +704,7 @@ public struct AsyncValueObservation: AsyncSequence { } let iterator = stream.makeAsyncIterator() - if let cancellable = cancellable { + if let cancellable { return Iterator( iterator: iterator, cancellable: cancellable) diff --git a/Tests/CombineExpectations/PublisherExpectations/Recording.swift b/Tests/CombineExpectations/PublisherExpectations/Recording.swift index fa3aff952..0b95292dc 100644 --- a/Tests/CombineExpectations/PublisherExpectations/Recording.swift +++ b/Tests/CombineExpectations/PublisherExpectations/Recording.swift @@ -49,7 +49,7 @@ extension PublisherExpectations { /// } public func get() throws -> Record.Recording { try recorder.value { (elements, completion, remainingElements, consume) in - if let completion = completion { + if let completion { consume(remainingElements.count) return Record.Recording(output: elements, completion: completion) } else { diff --git a/Tests/CombineExpectations/Recorder.swift b/Tests/CombineExpectations/Recorder.swift index 83d29fc53..48e981b27 100644 --- a/Tests/CombineExpectations/Recorder.swift +++ b/Tests/CombineExpectations/Recorder.swift @@ -253,7 +253,7 @@ public class Recorder: Subscriber { synchronized { switch state { case let .subscribed(_, exp, elements): - if let exp = exp { + if let exp { switch exp { case let .onCompletion(expectation): expectation.fulfill() diff --git a/Tests/GRDBTests/DatabaseConfigurationTests.swift b/Tests/GRDBTests/DatabaseConfigurationTests.swift index b0d4d2714..f217c17f0 100644 --- a/Tests/GRDBTests/DatabaseConfigurationTests.swift +++ b/Tests/GRDBTests/DatabaseConfigurationTests.swift @@ -39,7 +39,7 @@ class DatabaseConfigurationTests: GRDBTestCase { var configuration = Configuration() configuration.prepareDatabase { db in - if let error = error { + if let error { throw error } } diff --git a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift index 6e338372a..30df8d81b 100644 --- a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift +++ b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift @@ -238,7 +238,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { s2.signal() } let block2 = { [weak dbPool] () in - if let dbPool = dbPool { + if let dbPool { try! dbPool.read { db in s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -282,7 +282,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { let block2 = { [weak dbPool] () in var statement: Statement? = nil do { - if let dbPool = dbPool { + if let dbPool { do { try dbPool.write { db in statement = try db.makeStatement(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") diff --git a/Tests/GRDBTests/DatabaseQueueConcurrencyTests.swift b/Tests/GRDBTests/DatabaseQueueConcurrencyTests.swift index 0fcbd6329..613d6b5ad 100644 --- a/Tests/GRDBTests/DatabaseQueueConcurrencyTests.swift +++ b/Tests/GRDBTests/DatabaseQueueConcurrencyTests.swift @@ -103,7 +103,7 @@ class ConcurrencyTests: GRDBTestCase { _ = group.wait(timeout: .distantFuture) - if let concurrencyError = concurrencyError { + if let concurrencyError { XCTAssertEqual(concurrencyError.resultCode, .SQLITE_BUSY) XCTAssertEqual(concurrencyError.sql, "INSERT INTO stuffs (id) VALUES (NULL)") } else { @@ -159,7 +159,7 @@ class ConcurrencyTests: GRDBTestCase { _ = group.wait(timeout: .distantFuture) - if let concurrencyError = concurrencyError { + if let concurrencyError { XCTAssertEqual(concurrencyError.resultCode, .SQLITE_BUSY) XCTAssertEqual(concurrencyError.sql, "BEGIN EXCLUSIVE TRANSACTION") } else { @@ -215,7 +215,7 @@ class ConcurrencyTests: GRDBTestCase { _ = group.wait(timeout: .distantFuture) - if let concurrencyError = concurrencyError { + if let concurrencyError { XCTAssertEqual(concurrencyError.resultCode, .SQLITE_BUSY) XCTAssertEqual(concurrencyError.sql, "BEGIN IMMEDIATE TRANSACTION") } else { diff --git a/Tests/GRDBTests/DatabaseQueueReleaseMemoryTests.swift b/Tests/GRDBTests/DatabaseQueueReleaseMemoryTests.swift index 6868f8bb0..7c5b9428e 100644 --- a/Tests/GRDBTests/DatabaseQueueReleaseMemoryTests.swift +++ b/Tests/GRDBTests/DatabaseQueueReleaseMemoryTests.swift @@ -73,7 +73,7 @@ class DatabaseQueueReleaseMemoryTests: GRDBTestCase { s2.signal() } let block2 = { [weak dbQueue] () in - if let dbQueue = dbQueue { + if let dbQueue { try! dbQueue.write { db in s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -118,7 +118,7 @@ class DatabaseQueueReleaseMemoryTests: GRDBTestCase { let block2 = { [weak dbQueue] () in var statement: Statement? = nil do { - if let dbQueue = dbQueue { + if let dbQueue { do { try dbQueue.write { db in statement = try db.makeStatement(sql: "CREATE TABLE items (id INTEGER PRIMARY KEY)") diff --git a/Tests/GRDBTests/FoundationNSUUIDTests.swift b/Tests/GRDBTests/FoundationNSUUIDTests.swift index 0aaf75e2f..8cac824f7 100644 --- a/Tests/GRDBTests/FoundationNSUUIDTests.swift +++ b/Tests/GRDBTests/FoundationNSUUIDTests.swift @@ -4,7 +4,7 @@ import GRDB class FoundationNSUUIDTests: GRDBTestCase { private func assert(_ value: DatabaseValueConvertible?, isDecodedAs expectedUUID: NSUUID?) throws { try makeDatabaseQueue().read { db in - if let expectedUUID = expectedUUID { + if let expectedUUID { let decodedUUID = try NSUUID.fetchOne(db, sql: "SELECT ?", arguments: [value]) XCTAssertEqual(decodedUUID, expectedUUID) } else if value == nil { diff --git a/Tests/GRDBTests/FoundationUUIDTests.swift b/Tests/GRDBTests/FoundationUUIDTests.swift index d5f05ab30..4f0280500 100644 --- a/Tests/GRDBTests/FoundationUUIDTests.swift +++ b/Tests/GRDBTests/FoundationUUIDTests.swift @@ -5,7 +5,7 @@ import GRDB class FoundationUUIDTests: GRDBTestCase { private func assert(_ value: DatabaseValueConvertible?, isDecodedAs expectedUUID: UUID?) throws { try makeDatabaseQueue().read { db in - if let expectedUUID = expectedUUID { + if let expectedUUID { let decodedUUID = try UUID.fetchOne(db, sql: "SELECT ?", arguments: [value]) XCTAssertEqual(decodedUUID, expectedUUID) } else if value == nil { diff --git a/Tests/GRDBTests/RowAdapterTests.swift b/Tests/GRDBTests/RowAdapterTests.swift index bcf7a3f68..7fa4f3c36 100644 --- a/Tests/GRDBTests/RowAdapterTests.swift +++ b/Tests/GRDBTests/RowAdapterTests.swift @@ -631,7 +631,7 @@ class AdapterRowTests : RowTestCase { copiedRow = baseRow.copy() } - if let copiedRow = copiedRow { + if let copiedRow { XCTAssertEqual(copiedRow.count, 3) XCTAssertEqual(copiedRow["a"] as Int, 0) XCTAssertEqual(copiedRow["b"] as Int, 1) @@ -668,7 +668,7 @@ class AdapterRowTests : RowTestCase { row = baseRow.copy() XCTAssertEqual(row, baseRow) } - if let row = row { + if let row { let copiedRow = row.copy() XCTAssertEqual(row, copiedRow) } else { diff --git a/Tests/GRDBTests/TransactionObserverSavepointsTests.swift b/Tests/GRDBTests/TransactionObserverSavepointsTests.swift index fd700a450..b0df5932b 100644 --- a/Tests/GRDBTests/TransactionObserverSavepointsTests.swift +++ b/Tests/GRDBTests/TransactionObserverSavepointsTests.swift @@ -40,16 +40,16 @@ class TransactionObserverSavepointsTests: GRDBTestCase { private func match(preUpdateEvent event: DatabasePreUpdateEvent, kind: DatabasePreUpdateEvent.Kind, tableName: String, initialRowID: Int64?, finalRowID: Int64?, initialValues: [DatabaseValue]?, finalValues: [DatabaseValue]?, depth: CInt = 0) -> Bool { func check(_ dbValues: [DatabaseValue]?, expected: [DatabaseValue]?) -> Bool { - if let dbValues = dbValues { - guard let expected = expected else { return false } + if let dbValues { + guard let expected else { return false } return dbValues == expected } else { return expected == nil } } var count : Int = 0 - if let initialValues = initialValues { count = initialValues.count } - if let finalValues = finalValues { count = max(count, finalValues.count) } + if let initialValues { count = initialValues.count } + if let finalValues { count = max(count, finalValues.count) } guard (event.kind == kind) else { return false } guard (event.tableName == tableName) else { return false } diff --git a/Tests/GRDBTests/TransactionObserverTests.swift b/Tests/GRDBTests/TransactionObserverTests.swift index 446927342..386bbe21d 100644 --- a/Tests/GRDBTests/TransactionObserverTests.swift +++ b/Tests/GRDBTests/TransactionObserverTests.swift @@ -16,7 +16,7 @@ private class Observer : TransactionObserver { } deinit { - if let deinitBlock = deinitBlock { + if let deinitBlock { deinitBlock() } } @@ -57,7 +57,7 @@ private class Observer : TransactionObserver { func databaseWillCommit() throws { willCommitCount += 1 - if let commitError = commitError { + if let commitError { throw commitError } } @@ -144,16 +144,16 @@ class TransactionObserverTests: GRDBTestCase { private func match(preUpdateEvent event: DatabasePreUpdateEvent, kind: DatabasePreUpdateEvent.Kind, tableName: String, initialRowID: Int64?, finalRowID: Int64?, initialValues: [DatabaseValue]?, finalValues: [DatabaseValue]?, depth: CInt = 0) -> Bool { func check(_ dbValues: [DatabaseValue]?, expected: [DatabaseValue]?) -> Bool { - if let dbValues = dbValues { - guard let expected = expected else { return false } + if let dbValues { + guard let expected else { return false } return dbValues == expected } else { return expected == nil } } var count : Int = 0 - if let initialValues = initialValues { count = initialValues.count } - if let finalValues = finalValues { count = max(count, finalValues.count) } + if let initialValues { count = initialValues.count } + if let finalValues { count = max(count, finalValues.count) } guard (event.kind == kind) else { return false } guard (event.tableName == tableName) else { return false } diff --git a/Tests/GRDBTests/ValueObservationRecorder.swift b/Tests/GRDBTests/ValueObservationRecorder.swift index 2b585a740..297d54662 100644 --- a/Tests/GRDBTests/ValueObservationRecorder.swift +++ b/Tests/GRDBTests/ValueObservationRecorder.swift @@ -668,7 +668,7 @@ extension ValueObservationExpectations { consume(1) return next } - if let error = error { + if let error { throw error } else { throw ValueRecordingError.notEnoughValues @@ -696,7 +696,7 @@ extension ValueObservationExpectations { if remainingValues.isEmpty == false { return } - if let error = error { + if let error { throw error } } @@ -732,7 +732,7 @@ extension ValueObservationExpectations { consume(count) return Array(remainingValues.prefix(count)) } - if let error = error { + if let error { throw error } else { throw ValueRecordingError.notEnoughValues @@ -783,7 +783,7 @@ extension ValueObservationExpectations { consume(extraCount) return Array(values.prefix(matchedCount)) } - if let error = error { + if let error { throw error } consume(remainingValues.count) @@ -807,7 +807,7 @@ extension ValueObservationExpectations { public func get() throws -> (values: [Value], error: Error) { try recorder.value { (values, error, remainingValues, consume) in - if let error = error { + if let error { consume(remainingValues.count) return (values: values, error: error) } else {