X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FERecord.java;h=a41c0f042d46034e782ec06b78888bfe146cf7c9;hb=527940f032d9dd8ebd4c7bd202356115f1715120;hp=cbb69a34be75153b04d99a9d78ccb234676a9194;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java index cbb69a34b..a41c0f042 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java @@ -52,8 +52,32 @@ public class ERecord extends ASTExpression { return new EError(constructor.location); } THashMap recordMap = new THashMap(fields.length); - for(FieldAssignment field : fields) - recordMap.put(field.name, field); + for(FieldAssignment field : fields) { + if(field.value == null) { + String actualName = field.name; + if(actualName.charAt(0) == '?') + actualName = actualName.substring(1); + String bestMatch = null; + int bestMatchLength = 0; + for(int i=0;i bestMatchLength) { + bestMatch = fieldName; + bestMatchLength = fieldName.length(); + } + } + if(bestMatch == null) { + context.getErrorLog().log(field.location, "Invalid shorthand field " + field.name + " is defined twice."); + return new EError(location); + } + field.value = new EVar(field.location, field.name); + field.name = bestMatch; + } + if(recordMap.put(field.name, field) != null) { + context.getErrorLog().log(field.location, "Field " + field.name + " is defined more than once."); + return new EError(location); + } + } Expression[] parameters = new Expression[fieldNames.length]; boolean error = false; for(int i=0;i