diff --git a/src/qir/types/QIRRecordType.java b/src/qir/types/QIRRecordType.java index 75c2a6a553cf21bb25a1bf0245202fea1a92e01b..f7bce1a202722bbbe6c11a5681be1495e78e439b 100644 --- a/src/qir/types/QIRRecordType.java +++ b/src/qir/types/QIRRecordType.java @@ -6,8 +6,6 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.stream.Collectors; -import qir.util.QIRException; - public class QIRRecordType extends QIRType { private final Map<String, QIRType> fieldTypes; private Optional<QIRType> globalRestriction; @@ -43,11 +41,11 @@ public class QIRRecordType extends QIRType { return fieldTypes.get(id); } - public final void unionWith(final QIRRecordType other) { + public final boolean unionWith(final QIRRecordType other) { if (!globalRestriction.isPresent() || other.globalRestriction.isPresent() && other.globalRestriction.get().isSubtypeOf(globalRestriction.get())) globalRestriction = other.globalRestriction; else if (other.globalRestriction.isPresent() && !globalRestriction.get().isSubtypeOf(other.globalRestriction.get())) - throw new QIRException("Failed union between " + this + " and " + other); + return false; for (Entry<String, QIRType> otherEntry : other.fieldTypes.entrySet()) { final String otherKey = otherEntry.getKey(); final QIRType otherValue = otherEntry.getValue(); @@ -56,10 +54,11 @@ public class QIRRecordType extends QIRType { if (otherValue.isSubtypeOf(thisType)) fieldTypes.put(otherKey, otherValue); else if (!thisType.isSubtypeOf(otherValue)) - throw new QIRException("Failed union between " + this + " and " + other); + return false; } else fieldTypes.put(otherEntry.getKey(), otherEntry.getValue()); } + return true; } @Override diff --git a/src/qir/types/QIRSomeType.java b/src/qir/types/QIRSomeType.java index e583630967e5d2183c34efcd386d8aeba0540d12..6f0fc9375313871d2223b2c74a603def2823f73d 100644 --- a/src/qir/types/QIRSomeType.java +++ b/src/qir/types/QIRSomeType.java @@ -2,8 +2,6 @@ package qir.types; import java.util.Optional; -import qir.util.QIRException; - public class QIRSomeType extends QIRType { private static int idGen = 0; @@ -25,18 +23,23 @@ public class QIRSomeType extends QIRType { @Override protected boolean isSubtypeOfSpecific(final QIRType other) { + if (other instanceof QIRRecordType) { + if (infered.isPresent()) { + if (infered.get() instanceof QIRRecordType) { + ((QIRRecordType) infered.get()).unionWith((QIRRecordType) other); + return true; + } else + return false; + } + infered = Optional.of(other); + return true; + } if (!infered.isPresent() || other.isSubtypeOf(infered.get())) { infered = Optional.of(other); return true; } if (infered.get().isSubtypeOf(other)) return true; - if (infered.get() instanceof QIRRecordType && other instanceof QIRRecordType) - try { - ((QIRRecordType) infered.get()).unionWith((QIRRecordType) other); - return true; - } catch (final QIRException e) { - } return false; } }