diff --git a/src/qir/types/QIRRecordType.java b/src/qir/types/QIRRecordType.java index f2ae48add0c12d3a6481745fc1b0b9d61e0783f3..75c2a6a553cf21bb25a1bf0245202fea1a92e01b 100644 --- a/src/qir/types/QIRRecordType.java +++ b/src/qir/types/QIRRecordType.java @@ -25,6 +25,13 @@ public class QIRRecordType extends QIRType { this.globalRestriction = globalRestriction; } + public QIRRecordType(final QIRRecordType other, final String id, final QIRType value) { + this.fieldTypes = new HashMap<>(); + other.fieldTypes.forEach((k, v) -> this.fieldTypes.put(k, v)); + this.fieldTypes.put(id, value); + this.globalRestriction = other.globalRestriction; + } + public static final QIRRecordType ANY = new QIRRecordType(new HashMap<>()); public static final QIRRecordType BOTTOM = new QIRRecordType(new HashMap<>()); @@ -32,8 +39,8 @@ public class QIRRecordType extends QIRType { return new QIRRecordType(new HashMap<>(), globalRestriction); } - public final Map<String, QIRType> getFieldTypes() { - return fieldTypes; + public final QIRType get(final String id) { + return fieldTypes.get(id); } public final void unionWith(final QIRRecordType other) { diff --git a/src/qir/typing/QIRDefaultTypeSystemVisitor.java b/src/qir/typing/QIRDefaultTypeSystemVisitor.java index 515804fc1b889f268dfc9df7724414d45161125e..a7a36ff0ea91aa9ff4d2cc24f1b32d9e7d886c9e 100644 --- a/src/qir/typing/QIRDefaultTypeSystemVisitor.java +++ b/src/qir/typing/QIRDefaultTypeSystemVisitor.java @@ -235,12 +235,7 @@ public class QIRDefaultTypeSystemVisitor extends QIRTypeSystemVisitor { } public QIRType visit(final QIRRcons qirRcons) { - final QIRRecordType tailType = expectIfSubtype(qirRcons.getTail().accept(this), anyRecordType); - - final Map<String, QIRType> fieldTypes = new HashMap<>(); - tailType.getFieldTypes().entrySet().forEach(e -> fieldTypes.put(e.getKey(), e.getValue())); - fieldTypes.put(qirRcons.getId(), qirRcons.getValue().accept(this)); - return new QIRRecordType(fieldTypes); + return new QIRRecordType(expectIfSubtype(qirRcons.getTail().accept(this), anyRecordType), qirRcons.getId(), qirRcons.getValue().accept(this)); } protected QIRType visit(final QIRRdestr qirRdestr, final Optional<QIRType> globalRecordRestriction) { @@ -249,7 +244,7 @@ public class QIRDefaultTypeSystemVisitor extends QIRTypeSystemVisitor { final QIRRecordType expectedRecordType = new QIRRecordType(expectedRecordFields, globalRecordRestriction); expectedRecordFields.put(colName, new QIRSomeType()); - return expectIfSubtype(qirRdestr.getRecord().accept(this), expectedRecordType).getFieldTypes().get(colName); + return expectIfSubtype(qirRdestr.getRecord().accept(this), expectedRecordType).get(colName); } public QIRType visit(final QIRRdestr qirRdestr) {