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