From e4d8e4d61b038b73524bc78627d502995390a5bc Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 11 Sep 2013 00:04:02 +0400 Subject: [PATCH] Not ignoring other properties in scope. First one (almost randomly) was chosen instead of ambiguity. --- .../jet/lang/resolve/DescriptorUtils.java | 10 ---------- .../tasks/CallableDescriptorCollectors.java | 17 +++++++++++------ .../tests/scopes/AmbiguousNonExtensions.kt | 18 ++++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 4 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 613430dbda0..de499da73c1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -195,16 +195,6 @@ public class DescriptorUtils { return false; } - @Nullable - public static VariableDescriptor filterNonExtensionProperty(Collection variables) { - for (VariableDescriptor variable : variables) { - if (variable.getReceiverParameter() == null) { - return variable; - } - } - return null; - } - @NotNull public static JetType getFunctionExpectedReturnType(@NotNull FunctionDescriptor descriptor, @NotNull JetElement function) { JetType expectedType; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/CallableDescriptorCollectors.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/CallableDescriptorCollectors.java index 51f59f312b8..a01738101df 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/CallableDescriptorCollectors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/CallableDescriptorCollectors.java @@ -20,7 +20,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.ErrorUtils; @@ -84,12 +83,18 @@ public class CallableDescriptorCollectors { @NotNull @Override public Collection getNonExtensionsByName(JetScope scope, Name name) { - VariableDescriptor descriptor = scope.getLocalVariable(name); - if (descriptor == null) { - descriptor = DescriptorUtils.filterNonExtensionProperty(scope.getProperties(name)); + VariableDescriptor localVariable = scope.getLocalVariable(name); + if (localVariable != null) { + return Collections.singleton(localVariable); } - if (descriptor == null) return Collections.emptyList(); - return Collections.singleton(descriptor); + + LinkedHashSet variables = Sets.newLinkedHashSet(); + for (VariableDescriptor variable : scope.getProperties(name)) { + if (variable.getReceiverParameter() == null) { + variables.add(variable); + } + } + return variables; } @NotNull diff --git a/compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.kt b/compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.kt new file mode 100644 index 00000000000..2ea728f0fee --- /dev/null +++ b/compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.kt @@ -0,0 +1,18 @@ +// FILE: a.kt +package a + +val v = 1 +fun f() = 1 + +// FILE: b.kt +package b + +val v = 1 +fun f() = 1 + +// FILE: main.kt +import a.* +import b.* + +val vv = v +val ff = f() diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 7e5170cfd2a..db0573b15d4 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -5034,6 +5034,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/scopes/AmbiguityBetweenRootAndPackage.kt"); } + @TestMetadata("AmbiguousNonExtensions.kt") + public void testAmbiguousNonExtensions() throws Exception { + doTest("compiler/testData/diagnostics/tests/scopes/AmbiguousNonExtensions.kt"); + } + @TestMetadata("ImportFromCurrentWithDifferentName.kt") public void testImportFromCurrentWithDifferentName() throws Exception { doTest("compiler/testData/diagnostics/tests/scopes/ImportFromCurrentWithDifferentName.kt");