Passing DataFlowInfo when analyzing property initializers
#KT-2835 In Progress #KT-2225 In Progress #KT-338 In Progress
This commit is contained in:
@@ -204,7 +204,12 @@ public class DeclarationResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitProperty(JetProperty property) {
|
public void visitProperty(JetProperty property) {
|
||||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(namespaceLike.getOwnerForChildren(), scopeForPropertyInitializers, property, trace);
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(
|
||||||
|
namespaceLike.getOwnerForChildren(),
|
||||||
|
scopeForPropertyInitializers,
|
||||||
|
property,
|
||||||
|
trace,
|
||||||
|
context.getOuterDataFlowInfo());
|
||||||
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||||
context.getProperties().put(property, propertyDescriptor);
|
context.getProperties().put(property, propertyDescriptor);
|
||||||
context.registerDeclaringScope(property, scopeForPropertyInitializers);
|
context.registerDeclaringScope(property, scopeForPropertyInitializers);
|
||||||
|
|||||||
@@ -941,7 +941,8 @@ public class DescriptorResolver {
|
|||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull JetScope scope,
|
@NotNull JetScope scope,
|
||||||
@NotNull JetProperty property,
|
@NotNull JetProperty property,
|
||||||
BindingTrace trace
|
@NotNull BindingTrace trace,
|
||||||
|
@NotNull DataFlowInfo dataFlowInfo
|
||||||
) {
|
) {
|
||||||
|
|
||||||
JetModifierList modifierList = property.getModifierList();
|
JetModifierList modifierList = property.getModifierList();
|
||||||
@@ -994,7 +995,7 @@ public class DescriptorResolver {
|
|||||||
JetScope propertyScope = getPropertyDeclarationInnerScope(propertyDescriptor, scope, typeParameterDescriptors,
|
JetScope propertyScope = getPropertyDeclarationInnerScope(propertyDescriptor, scope, typeParameterDescriptors,
|
||||||
NO_RECEIVER_PARAMETER, trace);
|
NO_RECEIVER_PARAMETER, trace);
|
||||||
|
|
||||||
JetType type = getVariableType(propertyDescriptor, propertyScope, property, DataFlowInfo.EMPTY, true, trace);
|
JetType type = getVariableType(propertyDescriptor, propertyScope, property, dataFlowInfo, true, trace);
|
||||||
|
|
||||||
propertyDescriptor.setType(type, typeParameterDescriptors, getExpectedThisObjectIfNeeded(containingDeclaration),
|
propertyDescriptor.setType(type, typeParameterDescriptors, getExpectedThisObjectIfNeeded(containingDeclaration),
|
||||||
receiverDescriptor);
|
receiverDescriptor);
|
||||||
@@ -1031,7 +1032,7 @@ public class DescriptorResolver {
|
|||||||
@NotNull final JetVariableDeclaration variable,
|
@NotNull final JetVariableDeclaration variable,
|
||||||
@NotNull final DataFlowInfo dataFlowInfo,
|
@NotNull final DataFlowInfo dataFlowInfo,
|
||||||
boolean notLocal,
|
boolean notLocal,
|
||||||
final BindingTrace trace
|
@NotNull final BindingTrace trace
|
||||||
) {
|
) {
|
||||||
JetTypeReference propertyTypeRef = variable.getTypeRef();
|
JetTypeReference propertyTypeRef = variable.getTypeRef();
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -186,9 +186,13 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
for (JetProperty propertyDeclaration : declarations) {
|
for (JetProperty propertyDeclaration : declarations) {
|
||||||
JetScope resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration);
|
JetScope resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration);
|
||||||
PropertyDescriptor propertyDescriptor =
|
PropertyDescriptor propertyDescriptor =
|
||||||
resolveSession.getInjector().getDescriptorResolver().resolvePropertyDescriptor(thisDescriptor, resolutionScope,
|
resolveSession.getInjector().getDescriptorResolver().resolvePropertyDescriptor(
|
||||||
propertyDeclaration,
|
thisDescriptor, resolutionScope,
|
||||||
resolveSession.getTrace());
|
propertyDeclaration,
|
||||||
|
resolveSession.getTrace(),
|
||||||
|
// this relies on the assumption that a lazily resolved declaration is not a local one,
|
||||||
|
// thus doesn't have a surrounding data flow
|
||||||
|
DataFlowInfo.EMPTY);
|
||||||
result.add(propertyDescriptor);
|
result.add(propertyDescriptor);
|
||||||
resolveSession.getInjector().getAnnotationResolver().resolveAnnotationsArguments(propertyDescriptor, resolveSession.getTrace(), resolutionScope);
|
resolveSession.getInjector().getAnnotationResolver().resolveAnnotationsArguments(propertyDescriptor, resolveSession.getTrace(), resolutionScope);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fun test(x: Any?) {
|
||||||
|
if (x !is String) return
|
||||||
|
class C {
|
||||||
|
val v = x.length
|
||||||
|
}
|
||||||
|
object {
|
||||||
|
val v = x.length
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1486,6 +1486,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/dataFlow/local/LocalObjectDelegation.kt");
|
doTest("compiler/testData/diagnostics/tests/dataFlow/local/LocalObjectDelegation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PropertyInLocalClass.kt")
|
||||||
|
public void testPropertyInLocalClass() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/dataFlow/local/PropertyInLocalClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test innerSuite() {
|
public static Test innerSuite() {
|
||||||
|
|||||||
@@ -126,7 +126,8 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||||
JetProperty property = (JetProperty) declarations.get(0);
|
JetProperty property = (JetProperty) declarations.get(0);
|
||||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE);
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property,
|
||||||
|
JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
|
||||||
|
|
||||||
assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
|
assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
|
||||||
}
|
}
|
||||||
@@ -138,7 +139,8 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||||
JetProperty property = (JetProperty) declarations.get(0);
|
JetProperty property = (JetProperty) declarations.get(0);
|
||||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE);
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property,
|
||||||
|
JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
|
||||||
PropertyAccessorDescriptor propertyAccessor = isGetter
|
PropertyAccessorDescriptor propertyAccessor = isGetter
|
||||||
? propertyDescriptor.getGetter()
|
? propertyDescriptor.getGetter()
|
||||||
: propertyDescriptor.getSetter();
|
: propertyDescriptor.getSetter();
|
||||||
|
|||||||
Reference in New Issue
Block a user