| ... | ... | @@ -1573,7 +1573,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: |
| 1573 | 1573 | // .UseLast => {}, |
| 1574 | 1574 | // } |
| 1575 | 1575 | if (options.duplicate_field_behavior == .UseFirst) { |
| 1576 | | break; |
| 1576 | // do nothing, check of fields_seen[i] below will parse value without overwriting field |
| 1577 | 1577 | } else if (options.duplicate_field_behavior == .Error) { |
| 1578 | 1578 | return error.DuplicateJSONField; |
| 1579 | 1579 | } else if (options.duplicate_field_behavior == .UseLast) { |
| ... | ... | @@ -1586,7 +1586,11 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: |
| 1586 | 1586 | return error.UnexpectedValue; |
| 1587 | 1587 | } |
| 1588 | 1588 | } else { |
| 1589 | | @field(r, field.name) = try parse(field.field_type, tokens, options); |
| 1589 | if (fields_seen[i]) { |
| 1590 | parseFree(field.field_type, try parse(field.field_type, tokens, options), options); |
| 1591 | } else { |
| 1592 | @field(r, field.name) = try parse(field.field_type, tokens, options); |
| 1593 | } |
| 1590 | 1594 | } |
| 1591 | 1595 | fields_seen[i] = true; |
| 1592 | 1596 | found = true; |
| ... | ... | @@ -2013,6 +2017,9 @@ test "parse into struct with duplicate field" { |
| 2013 | 2017 | |
| 2014 | 2018 | const T2 = struct { a: f64 }; |
| 2015 | 2019 | try testing.expectEqual(T2{ .a = 0.25 }, try parse(T2, &TokenStream.init(str), options)); |
| 2020 | try testing.expectEqual(T2{ .a = 1.0 }, try parse(T2, &TokenStream.init(str), |
| 2021 | .{ .duplicate_field_behavior = .UseFirst } |
| 2022 | )); |
| 2016 | 2023 | } |
| 2017 | 2024 | |
| 2018 | 2025 | /// A non-stream JSON parser which constructs a tree of Value's. |