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=32999dcb48877a689c980d7e7c1bc73973b46345;hb=e73c1660b2f4d2a03784451e9e6afe1552b00877;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..32999dcb4 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,29 @@ 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 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