From ecc3fc662064dc0c003404219101e5ac529ddc5c Mon Sep 17 00:00:00 2001 From: Kuniwak Date: Fri, 1 Jun 2018 14:40:58 +0900 Subject: [PATCH] Use temporary vaiables to avoid type inference problem on Swift 4.0.x Related #36 --- Sources/Diffable+PrettyPrintable.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Sources/Diffable+PrettyPrintable.swift b/Sources/Diffable+PrettyPrintable.swift index 0a5b3ef..c7cd88a 100644 --- a/Sources/Diffable+PrettyPrintable.swift +++ b/Sources/Diffable+PrettyPrintable.swift @@ -200,7 +200,11 @@ extension Diffable: PrettyPrintable { let head: PrettyLine = .line("struct \(type) {") let tail: PrettyLine = .line("}") - return [head] + childLines(by: entries) + [tail] + // XXX: This temporary variable is necessary for Swift 4.0.x. + // Type inference could be failed if the temporary variable is nothing. + let body: [PrettyLine] = childLines(by: entries) + + return [head] + body + [tail] case let .anyClass(type: type, entries: entries): if entries.isEmpty { @@ -219,7 +223,11 @@ extension Diffable: PrettyPrintable { let head: PrettyLine = .line("class \(type) {") let tail: PrettyLine = .line("}") - return [head] + childLines(by: entries) + [tail] + // XXX: This temporary variable is necessary for Swift 4.0.x. + // Type inference could be failed if the temporary variable is nothing. + let body: [PrettyLine] = childLines(by: entries) + + return [head] + body + [tail] case let .minorCustomReflectable(type: type, content: content): switch content { @@ -239,7 +247,11 @@ extension Diffable: PrettyPrintable { let head: PrettyLine = .line("(unknown) \(type): CustomReflectable {") let tail: PrettyLine = .line("}") - return [head] + childLines(by: entries) + [tail] + // XXX: This temporary variable is necessary for Swift 4.0.x. + // Type inference could be failed if the temporary variable is nothing. + let body: [PrettyLine] = childLines(by: entries) + + return [head] + body + [tail] } case let .unrecognizable(debugInfo):