private static boolean isMoreSpecific( @NotNull CallableMemberDescriptor a, @NotNull CallableMemberDescriptor b) { if (a instanceof SimpleFunctionDescriptor) { assert b instanceof SimpleFunctionDescriptor : "b is " + b.getClass(); JetType aReturnType = a.getReturnType(); assert aReturnType != null; JetType bReturnType = b.getReturnType(); assert bReturnType != null; return JetTypeChecker.DEFAULT.isSubtypeOf(aReturnType, bReturnType); } if (a instanceof PropertyDescriptor) { assert b instanceof PropertyDescriptor : "b is " + b.getClass(); if (((PropertyDescriptor) a).isVar() || ((PropertyDescriptor) b).isVar()) { return ((PropertyDescriptor) a).isVar(); } // both vals return JetTypeChecker.DEFAULT.isSubtypeOf( ((PropertyDescriptor) a).getType(), ((PropertyDescriptor) b).getType()); } throw new IllegalArgumentException("Unexpected callable: " + a.getClass()); }
private void assertSubtypingRelation(String subtype, String supertype, boolean expected) { JetType typeNode1 = makeType(subtype); JetType typeNode2 = makeType(supertype); boolean result = JetTypeChecker.DEFAULT.isSubtypeOf(typeNode1, typeNode2); String modifier = expected ? "not " : ""; assertTrue(typeNode1 + " is " + modifier + "a subtype of " + typeNode2, result == expected); }
private static boolean isArgumentTypeValid( BindingContext bindingContext, JetValueArgument argument, ValueParameterDescriptor param) { if (argument.getArgumentExpression() != null) { JetType paramType = getActualParameterType(param); JetType exprType = bindingContext.getType(argument.getArgumentExpression()); return exprType == null || JetTypeChecker.DEFAULT.isSubtypeOf(exprType, paramType); } return false; }
public boolean isBooleanOrSubtype(@NotNull JetType type) { return JetTypeChecker.DEFAULT.isSubtypeOf(type, getBooleanType()); }