[FIX](struct)fix struct literal in fe const fold with field name #29735

This commit is contained in:
amory
2024-01-09 22:53:17 +08:00
committed by yiguolei
parent 71b017efee
commit fe5b0e9880
2 changed files with 11 additions and 5 deletions

View File

@ -101,7 +101,12 @@ public class StructLiteral extends LiteralExpr {
@Override
public String getStringValueInFe() {
List<String> list = new ArrayList<>(children.size());
children.forEach(v -> list.add(getStringLiteralForComplexType(v)));
// same with be default field index start with 1
for (int i = 0; i < children.size(); i++) {
Expr child = children.get(i);
String fieldName = new StructField(child.getType()).getName();
list.add("\"" + fieldName + (i + 1) + "\": " + getStringLiteralForComplexType(child));
}
return "{" + StringUtils.join(list, ", ") + "}";
}