| ... | @@ -1534,30 +1534,25 @@ fn parseInternal( | ... | @@ -1534,30 +1534,25 @@ fn parseInternal( |
| 1534 | child_options.allow_trailing_data = true; | 1534 | child_options.allow_trailing_data = true; |
| 1535 | var found = false; | 1535 | var found = false; |
| 1536 | inline for (structInfo.fields, 0..) |field, i| { | 1536 | inline for (structInfo.fields, 0..) |field, i| { |
| 1537 | // TODO: using switches here segfault the compiler (#2727?) | 1537 | if (switch (stringToken.escapes) { |
| 1538 | if ((stringToken.escapes == .None and mem.eql(u8, field.name, key_source_slice)) or (stringToken.escapes == .Some and (field.name.len == stringToken.decodedLength() and encodesTo(field.name, key_source_slice)))) { | 1538 | .None => mem.eql(u8, field.name, key_source_slice), |
| 1539 | // if (switch (stringToken.escapes) { | 1539 | .Some => (field.name.len == stringToken.decodedLength() and encodesTo(field.name, key_source_slice)), |
| 1540 | // .None => mem.eql(u8, field.name, key_source_slice), | 1540 | }) { |
| 1541 | // .Some => (field.name.len == stringToken.decodedLength() and encodesTo(field.name, key_source_slice)), | | |
| 1542 | // }) { | | |
| 1543 | if (fields_seen[i]) { | 1541 | if (fields_seen[i]) { |
| 1544 | // switch (options.duplicate_field_behavior) { | 1542 | switch (options.duplicate_field_behavior) { |
| 1545 | // .UseFirst => {}, | 1543 | .UseFirst => { |
| 1546 | // .Error => {}, | 1544 | // unconditonally ignore value. for comptime fields, this skips check against default_value |
| 1547 | // .UseLast => {}, | 1545 | parseFree(field.type, try parse(field.type, tokens, child_options), child_options); |
| 1548 | // } | 1546 | found = true; |
| 1549 | if (options.duplicate_field_behavior == .UseFirst) { | 1547 | break; |
| 1550 | // unconditonally ignore value. for comptime fields, this skips check against default_value | 1548 | }, |
| 1551 | parseFree(field.type, try parse(field.type, tokens, child_options), child_options); | 1549 | .Error => return error.DuplicateJSONField, |
| 1552 | found = true; | 1550 | .UseLast => { |
| 1553 | break; | 1551 | if (!field.is_comptime) { |
| 1554 | } else if (options.duplicate_field_behavior == .Error) { | 1552 | parseFree(field.type, @field(r, field.name), child_options); |
| 1555 | return error.DuplicateJSONField; | 1553 | } |
| 1556 | } else if (options.duplicate_field_behavior == .UseLast) { | 1554 | fields_seen[i] = false; |
| 1557 | if (!field.is_comptime) { | 1555 | }, |
| 1558 | parseFree(field.type, @field(r, field.name), child_options); | | |
| 1559 | } | | |
| 1560 | fields_seen[i] = false; | | |
| 1561 | } | 1556 | } |
| 1562 | } | 1557 | } |
| 1563 | if (field.is_comptime) { | 1558 | if (field.is_comptime) { |