950 LOWER(InferenceBound.LOWER) { |
950 LOWER(InferenceBound.LOWER) { |
951 @Override |
951 @Override |
952 Type solve(UndetVar uv, InferenceContext inferenceContext) { |
952 Type solve(UndetVar uv, InferenceContext inferenceContext) { |
953 Infer infer = inferenceContext.infer(); |
953 Infer infer = inferenceContext.infer(); |
954 List<Type> lobounds = filterBounds(uv, inferenceContext); |
954 List<Type> lobounds = filterBounds(uv, inferenceContext); |
955 Type owntype = infer.types.lub(lobounds); |
955 //note: lobounds should have at least one element |
956 if (owntype.hasTag(ERROR)) { |
956 Type owntype = lobounds.tail.tail == null ? lobounds.head : infer.types.lub(lobounds); |
|
957 if (owntype.isPrimitive() || owntype.hasTag(ERROR)) { |
957 throw infer.inferenceException |
958 throw infer.inferenceException |
958 .setMessage("no.unique.minimal.instance.exists", |
959 .setMessage("no.unique.minimal.instance.exists", |
959 uv.qtype, lobounds); |
960 uv.qtype, lobounds); |
960 } else { |
961 } else { |
961 return owntype; |
962 return owntype; |
969 UPPER(InferenceBound.UPPER) { |
970 UPPER(InferenceBound.UPPER) { |
970 @Override |
971 @Override |
971 Type solve(UndetVar uv, InferenceContext inferenceContext) { |
972 Type solve(UndetVar uv, InferenceContext inferenceContext) { |
972 Infer infer = inferenceContext.infer(); |
973 Infer infer = inferenceContext.infer(); |
973 List<Type> hibounds = filterBounds(uv, inferenceContext); |
974 List<Type> hibounds = filterBounds(uv, inferenceContext); |
974 Type owntype = infer.types.glb(hibounds); |
975 //note: lobounds should have at least one element |
975 if (owntype.isErroneous()) { |
976 Type owntype = hibounds.tail.tail == null ? hibounds.head : infer.types.glb(hibounds); |
|
977 if (owntype.isPrimitive() || owntype.hasTag(ERROR)) { |
976 throw infer.inferenceException |
978 throw infer.inferenceException |
977 .setMessage("no.unique.maximal.instance.exists", |
979 .setMessage("no.unique.maximal.instance.exists", |
978 uv.qtype, hibounds); |
980 uv.qtype, hibounds); |
979 } else { |
981 } else { |
980 return owntype; |
982 return owntype; |
1098 checkWithinBounds(inferenceContext, warn); |
1100 checkWithinBounds(inferenceContext, warn); |
1099 continue outer; |
1101 continue outer; |
1100 } |
1102 } |
1101 } |
1103 } |
1102 //no progress |
1104 //no progress |
1103 throw inferenceException; |
1105 throw inferenceException.setMessage(); |
1104 } |
1106 } |
1105 } |
1107 } |
1106 catch (InferenceException ex) { |
1108 catch (InferenceException ex) { |
|
1109 //did we fail because of interdependent ivars? |
1107 inferenceContext.rollback(); |
1110 inferenceContext.rollback(); |
1108 instantiateAsUninferredVars(varsToSolve, inferenceContext); |
1111 instantiateAsUninferredVars(varsToSolve, inferenceContext); |
1109 checkWithinBounds(inferenceContext, warn); |
1112 checkWithinBounds(inferenceContext, warn); |
1110 } |
1113 } |
1111 inferenceGraph.deleteNode(nodeToSolve); |
1114 inferenceGraph.deleteNode(nodeToSolve); |