public void Unify(TypeVariableReference toUnify, TypeVariableReference toUnifyWith, ITypeUnificationResult unificationResult) { TypeBase toUnifyTypeBase = GetTypeForTypeVariableReference(toUnify), toUnifyWithTypeBase = GetTypeForTypeVariableReference(toUnifyWith); LiteralType toUnifyLiteral = toUnifyTypeBase as LiteralType, toUnifyWithLiteral = toUnifyWithTypeBase as LiteralType; if (toUnifyLiteral != null && toUnifyWithLiteral != null) { if (toUnifyLiteral.Type == toUnifyWithLiteral.Type) { MergeTypeVariableIntoTypeVariable(toUnify, toUnifyWith); return; } unificationResult.SetTypeMismatch(); return; } ConstructorType toUnifyConstructor = toUnifyTypeBase as ConstructorType, toUnifyWithConstructor = toUnifyWithTypeBase as ConstructorType; if (toUnifyConstructor != null && toUnifyWithConstructor != null) { if (toUnifyConstructor.ConstructorName == toUnifyWithConstructor.ConstructorName) { Unify(toUnifyConstructor.Argument, toUnifyWithConstructor.Argument, unificationResult); MergeTypeVariableIntoTypeVariable(toUnify, toUnifyWith); return; } unificationResult.SetTypeMismatch(); return; } ReferenceType toUnifyReference = toUnifyTypeBase as ReferenceType, toUnifyWithReference = toUnifyWithTypeBase as ReferenceType; if (toUnifyReference != null && toUnifyWithReference != null) { toUnifyReference.UnifyMutability(toUnifyWithReference); Unify(toUnifyReference.UnderlyingType, toUnifyWithReference.UnderlyingType, unificationResult); Unify(toUnifyReference.LifetimeType, toUnifyWithReference.LifetimeType, unificationResult); return; } LifetimeTypeContainer toUnifyLifetime = toUnifyTypeBase as LifetimeTypeContainer, toUnifyWithLifetime = toUnifyWithTypeBase as LifetimeTypeContainer; if (toUnifyLifetime != null && toUnifyWithLifetime != null) { // toUnify is the possible supertype container here toUnifyLifetime.AdoptLifetimeIfPossible(toUnifyWithLifetime.LifetimeValue); return; } TypeVariable toUnifyTypeVariable = toUnifyTypeBase as TypeVariable, toUnifyWithTypeVariable = toUnifyWithTypeBase as TypeVariable; if (toUnifyTypeVariable != null && toUnifyWithTypeVariable != null) { toUnifyWithTypeVariable.AdoptConstraintsFromVariable(toUnifyTypeVariable); MergeTypeVariableIntoTypeVariable(toUnify, toUnifyWith); return; } if (toUnifyTypeVariable != null) { UnifyTypeVariableWithNonTypeVariable(toUnify, toUnifyWith, unificationResult); return; } if (toUnifyWithTypeVariable != null) { UnifyTypeVariableWithNonTypeVariable(toUnifyWith, toUnify, unificationResult); return; } unificationResult.SetTypeMismatch(); return; }