Avatar
πŸ˜‚
Failed to produce diagnostic for expression; please file a bug report
3:43β€―AM
@_functionBuilder public struct DictionaryBuilder<Key: Hashable, Value> { public func buildBlock() -> [Key: Value] { [:] } public func buildBlock(_ c0: [Key: Value]) -> [Key: Value] { c0 } public func buildBlock(_ c0: [Key: Value], _ c1: [Key: Value]) -> [Key: Value] { c0.merging(c1) { _, new in new } } } extension Dictionary { public init(@DictionaryBuilder<Key, Value> _ builder: () -> [Key: Value]) { self = builder() } }
3:43β€―AM
import XCTest @testable import DictionaryBuilder final class DictionaryBuilderTests: XCTestCase { func testExample() { let dictionary: [String: Int] = .init { [ "a": 2, "b": 3, ] [ "c": 5, "d": 7, "e": 11, ] } XCTAssertEqual(dictionary, [ "a": 2, "b": 3, "c": 5, "d": 7, "e": 11, ]) } }
3:44β€―AM
γƒ’γ‚Έγƒ₯γƒΌγƒ«ζœ¬δ½“γ―γƒ“γƒ«γƒ‰γ§γγ‚‹γ‘γ©γƒ†γ‚Ήγƒˆγ§γ‚³γƒ³γƒ‘γ‚€γƒ©γŒ "Failed to produce diagnostic" に・・・。
3:44β€―AM
init はあやしいかと思って static func γ«γ—γ¦γΏγŸγ‘γ©ε€‰γ‚γ‚‰γšγ€‚