diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java index e1c9eca8ce1..dae5c829210 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java @@ -768,11 +768,14 @@ public class KtPsiUtil { return (KtElement) parent; } } - if (current instanceof KtBlockExpression || current instanceof KtParameter) { + if (current instanceof KtBlockExpression || current instanceof KtParameter || current instanceof KtValueArgument) { return (KtElement) current; } - if (current instanceof KtValueArgument) { - return (KtElement) current; + if (current instanceof KtDelegatedSuperTypeEntry) { + PsiElement grandParent = current.getParent().getParent(); + if (grandParent instanceof KtClassOrObject && !(grandParent.getParent() instanceof KtObjectLiteralExpression)) { + return (KtElement) grandParent; + } } current = parent; diff --git a/idea/testData/checker/ObjectLiteralInDelegate.kt b/idea/testData/checker/ObjectLiteralInDelegate.kt new file mode 100644 index 00000000000..f867b531175 --- /dev/null +++ b/idea/testData/checker/ObjectLiteralInDelegate.kt @@ -0,0 +1,14 @@ +// Test for KT-8187 +interface A { + fun get(x: Int) +} + +class B : A by object : A {} + +class C : A by (object : A {}) + +class D : A by 1 + (object : A {}) + +fun bar() { + val e = object : A by object : A {} {} +} diff --git a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java index fd061bda154..758dc525d3e 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java @@ -224,6 +224,12 @@ public class PsiCheckerTestGenerated extends AbstractPsiCheckerTest { doTest(fileName); } + @TestMetadata("ObjectLiteralInDelegate.kt") + public void testObjectLiteralInDelegate() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/ObjectLiteralInDelegate.kt"); + doTest(fileName); + } + @TestMetadata("Objects.kt") public void testObjects() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/Objects.kt");