Effective visibility: local is now considered private, TYPE_DEPENDS_ON_LOCAL_CLASS diagnostics removed as repeated #KT-9542 Fixed #KT-9526 Fixed
This commit is contained in:
@@ -399,9 +399,6 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<JetParameter> USELESS_VARARG_ON_PARAMETER = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<JetFunction, ClassDescriptor> FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS = DiagnosticFactory1.create(ERROR, DECLARATION_RETURN_TYPE);
|
||||
DiagnosticFactory1<JetProperty, ClassDescriptor> PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS = DiagnosticFactory1.create(ERROR, DECLARATION_RETURN_TYPE);
|
||||
|
||||
// Named parameters
|
||||
|
||||
DiagnosticFactory0<JetParameter> DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE = DiagnosticFactory0.create(ERROR, PARAMETER_DEFAULT_VALUE);
|
||||
|
||||
-2
@@ -270,8 +270,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNUSED_CHANGED_VALUE, "The value changed at ''{0}'' is never used", ELEMENT_TEXT);
|
||||
MAP.put(UNUSED_EXPRESSION, "The expression is unused");
|
||||
MAP.put(UNUSED_FUNCTION_LITERAL, "The function literal is unused. If you mean block, you can use 'run { ... }'");
|
||||
MAP.put(FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS, "Function return type depends on local class or object {0}", NAME);
|
||||
MAP.put(PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS, "Property type depends on local class or object {0}", NAME);
|
||||
|
||||
MAP.put(VAL_REASSIGNMENT, "Val cannot be reassigned", NAME);
|
||||
MAP.put(SETTER_PROJECTED_OUT, "Setter for ''{0}'' is removed by type projection", NAME);
|
||||
|
||||
@@ -689,58 +689,6 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkLocalTypesInFunctionReturnType(@NotNull JetFunction function, @NotNull FunctionDescriptor functionDescriptor) {
|
||||
if (functionDescriptor instanceof ConstructorDescriptor) return;
|
||||
if (!isExposedAsPublicAPI(functionDescriptor)) return;
|
||||
JetType returnType = functionDescriptor.getReturnType();
|
||||
if (returnType == null) return;
|
||||
checkLocalTypesExposedInType(function, functionDescriptor, returnType,
|
||||
FUNCTION_RETURN_TYPE_DEPENDS_ON_LOCAL_CLASS,
|
||||
new HashSet<JetType>());
|
||||
}
|
||||
|
||||
private void checkLocalTypesInPropertyType(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
if (!isExposedAsPublicAPI(propertyDescriptor)) return;
|
||||
JetType propertyType = propertyDescriptor.getType();
|
||||
checkLocalTypesExposedInType(property, propertyDescriptor, propertyType,
|
||||
PROPERTY_TYPE_DEPENDS_ON_LOCAL_CLASS,
|
||||
new HashSet<JetType>());
|
||||
}
|
||||
|
||||
private static boolean isExposedAsPublicAPI(@NotNull DeclarationDescriptor descriptor) {
|
||||
for (DeclarationDescriptor finger = descriptor; finger != null; finger = finger.getContainingDeclaration()) {
|
||||
if (finger instanceof DeclarationDescriptorWithVisibility) {
|
||||
Visibility visibility = ((DeclarationDescriptorWithVisibility) finger).getVisibility();
|
||||
if (Visibilities.isPrivate(visibility) || visibility == Visibilities.LOCAL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private <D extends JetDeclaration> void checkLocalTypesExposedInType(
|
||||
@NotNull D reportOnDeclaration,
|
||||
@NotNull DeclarationDescriptor parentDeclarationDescriptor,
|
||||
@NotNull JetType type,
|
||||
@NotNull DiagnosticFactory1<D, ClassDescriptor> diagnostic,
|
||||
@NotNull Set<JetType> visitedTypes
|
||||
) {
|
||||
visitedTypes.add(type);
|
||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(type);
|
||||
if (classDescriptor != null) {
|
||||
if (DescriptorUtils.isLocal(classDescriptor) && DescriptorUtils.isAncestor(parentDeclarationDescriptor, classDescriptor, true)) {
|
||||
trace.report(diagnostic.on(reportOnDeclaration, classDescriptor));
|
||||
}
|
||||
}
|
||||
for (TypeProjection projection : type.getArguments()) {
|
||||
JetType projectedType = projection.getType();
|
||||
if (!visitedTypes.contains(projectedType)) {
|
||||
checkLocalTypesExposedInType(reportOnDeclaration, parentDeclarationDescriptor, projectedType, diagnostic, visitedTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPropertyExposedType(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
EffectiveVisibility propertyVisibility = EffectiveVisibility.Companion.forMember(propertyDescriptor);
|
||||
EffectiveVisibility typeVisibility = EffectiveVisibility.Companion.forType(propertyDescriptor.getType());
|
||||
@@ -748,7 +696,6 @@ public class DeclarationsChecker {
|
||||
trace.report(EXPOSED_PROPERTY_TYPE.on(property, propertyVisibility, typeVisibility));
|
||||
}
|
||||
checkMemberReceiverExposedType(property.getReceiverTypeReference(), propertyDescriptor);
|
||||
checkLocalTypesInPropertyType(property, propertyDescriptor);
|
||||
}
|
||||
|
||||
protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) {
|
||||
@@ -818,7 +765,6 @@ public class DeclarationsChecker {
|
||||
i++;
|
||||
}
|
||||
checkMemberReceiverExposedType(function.getReceiverTypeReference(), functionDescriptor);
|
||||
checkLocalTypesInFunctionReturnType(function, functionDescriptor);
|
||||
}
|
||||
|
||||
private void checkAccessors(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
|
||||
Reference in New Issue
Block a user