Support underscores in non local destructuring declarations
This commit is contained in:
@@ -73,6 +73,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.*;
|
import org.jetbrains.kotlin.resolve.calls.model.*;
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
|
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject;
|
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject;
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.util.UnderscoreUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||||
@@ -3495,7 +3496,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
VariableDescriptor variableDescriptor = getVariableDescriptorNotNull(variableDeclaration);
|
VariableDescriptor variableDescriptor = getVariableDescriptorNotNull(variableDeclaration);
|
||||||
|
|
||||||
// Do not call `componentX` for destructuring entry called _
|
// Do not call `componentX` for destructuring entry called _
|
||||||
if (variableDescriptor.getName().isSpecial()) continue;
|
if (UnderscoreUtilKt.isSingleUnderscore(variableDeclaration)) continue;
|
||||||
|
|
||||||
if (asProperty && variableDescriptor instanceof PropertyDescriptor) {
|
if (asProperty && variableDescriptor instanceof PropertyDescriptor) {
|
||||||
StackValue.Property propertyValue = intermediateValueForProperty(
|
StackValue.Property propertyValue = intermediateValueForProperty(
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.resolve.DescriptorFactory;
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.util.UnderscoreUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature;
|
||||||
@@ -142,12 +143,14 @@ public class PropertyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void genDestructuringDeclaration(
|
private void genDestructuringDeclaration(
|
||||||
@Nullable KtDestructuringDeclarationEntry entry,
|
@NotNull KtDestructuringDeclarationEntry entry,
|
||||||
@NotNull PropertyDescriptor descriptor
|
@NotNull PropertyDescriptor descriptor
|
||||||
) {
|
) {
|
||||||
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.DEFAULT_IMPLS
|
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.DEFAULT_IMPLS
|
||||||
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
|
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
|
||||||
|
|
||||||
|
if (UnderscoreUtilKt.isSingleUnderscore(entry)) return;
|
||||||
|
|
||||||
genBackingFieldAndAnnotations(entry, descriptor, false);
|
genBackingFieldAndAnnotations(entry, descriptor, false);
|
||||||
|
|
||||||
generateGetter(entry, descriptor, null);
|
generateGetter(entry, descriptor, null);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
val (_, b, _) = A()
|
||||||
|
|
||||||
|
class A {
|
||||||
|
operator fun component1(): Int = throw RuntimeException()
|
||||||
|
operator fun component2() = 2
|
||||||
|
operator fun component3(): Int = throw RuntimeException()
|
||||||
|
}
|
||||||
|
|
||||||
|
// expected: b: 2
|
||||||
@@ -54,6 +54,12 @@ public class ScriptCodegenTestGenerated extends AbstractScriptCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("destructuringDeclarationUnderscore.kts")
|
||||||
|
public void testDestructuringDeclarationUnderscore() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/script/destructuringDeclarationUnderscore.kts");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("empty.kts")
|
@TestMetadata("empty.kts")
|
||||||
public void testEmpty() throws Exception {
|
public void testEmpty() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/script/empty.kts");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/script/empty.kts");
|
||||||
|
|||||||
Reference in New Issue
Block a user