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
|
||||
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);
|
||||
context.getProperties().put(property, propertyDescriptor);
|
||||
context.registerDeclaringScope(property, scopeForPropertyInitializers);
|
||||
|
||||
@@ -941,7 +941,8 @@ public class DescriptorResolver {
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull JetProperty property,
|
||||
BindingTrace trace
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
|
||||
JetModifierList modifierList = property.getModifierList();
|
||||
@@ -994,7 +995,7 @@ public class DescriptorResolver {
|
||||
JetScope propertyScope = getPropertyDeclarationInnerScope(propertyDescriptor, scope, typeParameterDescriptors,
|
||||
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),
|
||||
receiverDescriptor);
|
||||
@@ -1031,7 +1032,7 @@ public class DescriptorResolver {
|
||||
@NotNull final JetVariableDeclaration variable,
|
||||
@NotNull final DataFlowInfo dataFlowInfo,
|
||||
boolean notLocal,
|
||||
final BindingTrace trace
|
||||
@NotNull final BindingTrace trace
|
||||
) {
|
||||
JetTypeReference propertyTypeRef = variable.getTypeRef();
|
||||
|
||||
|
||||
+7
-3
@@ -186,9 +186,13 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
for (JetProperty propertyDeclaration : declarations) {
|
||||
JetScope resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration);
|
||||
PropertyDescriptor propertyDescriptor =
|
||||
resolveSession.getInjector().getDescriptorResolver().resolvePropertyDescriptor(thisDescriptor, resolutionScope,
|
||||
propertyDeclaration,
|
||||
resolveSession.getTrace());
|
||||
resolveSession.getInjector().getDescriptorResolver().resolvePropertyDescriptor(
|
||||
thisDescriptor, resolutionScope,
|
||||
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);
|
||||
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");
|
||||
}
|
||||
|
||||
@TestMetadata("PropertyInLocalClass.kt")
|
||||
public void testPropertyInLocalClass() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/dataFlow/local/PropertyInLocalClass.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
|
||||
@@ -126,7 +126,8 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
|
||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||
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());
|
||||
}
|
||||
@@ -138,7 +139,8 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
|
||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||
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
|
||||
? propertyDescriptor.getGetter()
|
||||
: propertyDescriptor.getSetter();
|
||||
|
||||
Reference in New Issue
Block a user