Put property delegates -related warnings on 'by'
This commit is contained in:
@@ -551,7 +551,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> ITERATOR_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory2<JetExpression, String, JetType> DELEGATE_SPECIAL_FUNCTION_MISSING = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory3<JetExpression, FunctionDescriptor, JetType, String> DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION = DiagnosticFactory3.create(WARNING);
|
||||
DiagnosticFactory3<PsiElement, FunctionDescriptor, JetType, String> DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION = DiagnosticFactory3.create(WARNING);
|
||||
DiagnosticFactory2<JetExpression, String, Collection<? extends ResolvedCall<?>>> DELEGATE_SPECIAL_FUNCTION_AMBIGUITY = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<JetExpression, String, Collection<? extends ResolvedCall<?>>> DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory3<JetExpression, String, JetType, JetType> DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR);
|
||||
|
||||
@@ -208,9 +208,6 @@ public class DelegatedPropertyResolver {
|
||||
}
|
||||
|
||||
FunctionDescriptor resultingDescriptor = functionResults.getResultingDescriptor();
|
||||
if (!resultingDescriptor.isOperator()) {
|
||||
OperatorValidator.Companion.report(delegateExpression, resultingDescriptor, trace);
|
||||
}
|
||||
|
||||
ResolvedCall<FunctionDescriptor> resultingCall = functionResults.getResultingCall();
|
||||
PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor);
|
||||
@@ -219,6 +216,11 @@ public class DelegatedPropertyResolver {
|
||||
JetPropertyDelegate delegate = property.getDelegate();
|
||||
if (delegate != null) {
|
||||
PsiElement byKeyword = delegate.getByKeywordNode().getPsi();
|
||||
|
||||
if (!resultingDescriptor.isOperator()) {
|
||||
OperatorValidator.Companion.report(byKeyword, resultingDescriptor, trace);
|
||||
}
|
||||
|
||||
symbolUsageValidator.validateCall(resultingCall, resultingCall.getResultingDescriptor(), trace, byKeyword);
|
||||
}
|
||||
}
|
||||
@@ -276,8 +278,19 @@ public class DelegatedPropertyResolver {
|
||||
fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, oldFunctionName, delegateExpression);
|
||||
if (additionalResolutionResult.getSecond().isSuccess()) {
|
||||
FunctionDescriptor resultingDescriptor = additionalResolutionResult.getSecond().getResultingDescriptor();
|
||||
trace.report(DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION.on(
|
||||
delegateExpression, resultingDescriptor, delegateType, functionName.asString()));
|
||||
|
||||
PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor);
|
||||
if (declaration instanceof JetProperty) {
|
||||
JetProperty property = (JetProperty) declaration;
|
||||
JetPropertyDelegate delegate = property.getDelegate();
|
||||
if (delegate != null) {
|
||||
PsiElement byKeyword = delegate.getByKeywordNode().getPsi();
|
||||
|
||||
trace.report(DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION.on(
|
||||
byKeyword, resultingDescriptor, delegateType, functionName.asString()));
|
||||
}
|
||||
}
|
||||
|
||||
trace.record(BindingContext.DELEGATED_PROPERTY_CALL, accessor, additionalResolutionResult.getFirst());
|
||||
return additionalResolutionResult.getSecond();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class OperatorValidator : SymbolUsageValidator {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun report(element: JetElement, descriptor: FunctionDescriptor, sink: DiagnosticSink) {
|
||||
fun report(element: PsiElement, descriptor: FunctionDescriptor, sink: DiagnosticSink) {
|
||||
if (!checkNotErrorOrDynamic(descriptor)) return
|
||||
|
||||
val containingDeclaration = descriptor.containingDeclaration
|
||||
|
||||
+3
-3
@@ -33,8 +33,8 @@ operator fun CustomDelegate3.setValue(thisRef: Any?, prop: <!DEPRECATION!>Proper
|
||||
|
||||
class Example {
|
||||
|
||||
var a by <!DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION, DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION!>CustomDelegate()<!>
|
||||
val aval by <!DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION!>CustomDelegate()<!>
|
||||
var a <!DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION, DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION!>by<!> CustomDelegate()
|
||||
val aval <!DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION!>by<!> CustomDelegate()
|
||||
var b by OkDelegate()
|
||||
var c by CustomDelegate2()
|
||||
var d by CustomDelegate3()
|
||||
@@ -50,4 +50,4 @@ class Example {
|
||||
fun requireString(s: String) {}
|
||||
fun requireInt(n: Int) {}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,5 @@ class CustomDelegate
|
||||
operator fun CustomDelegate.get(thisRef: Any?, prop: PropertyMetadata): String = ""
|
||||
|
||||
class Example {
|
||||
val a: String by <caret>CustomDelegate()
|
||||
val a: String <caret>by CustomDelegate()
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ class CustomDelegate {
|
||||
}
|
||||
|
||||
class Example {
|
||||
var a: String by <caret>CustomDelegate()
|
||||
var a: String <caret>by CustomDelegate()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user