KT-3856 Wrong inner class inaccessible diagnostic for extension to outer class

#KT-3856 Fixed
This commit is contained in:
Stanislav Erokhin
2016-02-16 18:36:26 +03:00
parent 61cc8394e8
commit 7de2013a3e
5 changed files with 108 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -230,6 +230,13 @@ class CandidateResolver(
}
private fun checkOuterClassMemberIsAccessible(context: CallCandidateResolutionContext<*>): Boolean {
fun KtElement.insideScript() = (containingFile as? KtFile)?.isScript ?: false
// context.scope doesn't contains outer class implicit receiver if we inside nested class
// Outer scope for some class in script file is scopeForInitializerResolution see: DeclarationScopeProviderImpl.getResolutionScopeForDeclaration
if (!context.call.callElement.insideScript()) return true
// In "this@Outer.foo()" the error will be reported on "this@Outer" instead
if (context.call.getExplicitReceiver() != null || context.call.getDispatchReceiver() != null) return true
@@ -0,0 +1,33 @@
fun foo(<!UNUSED_PARAMETER!>init<!>: A.() -> Unit) { }
class A {
var x: Int = 0
companion object {
val f = foo() {
x = 1
}
}
}
class B(val a: String) {
fun f() = 0
companion object {
fun B.bar() = a + f()
}
}
open class C {
fun bar() {}
}
class E: C() {
class D {
init {
with(C()) {
bar()
this.bar()
}
}
}
}
@@ -0,0 +1,59 @@
package
public fun foo(/*0*/ init: A.() -> kotlin.Unit): kotlin.Unit
public final class A {
public constructor A()
public final var x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public final val f: kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public final class B {
public constructor B(/*0*/ a: kotlin.String)
public final val a: kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun f(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final fun B.bar(): kotlin.String
}
}
public open class C {
public constructor C()
public final fun bar(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class E : C {
public constructor E()
public final override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final class D {
public constructor D()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -27,8 +27,8 @@ open class A<T> : J() {
fun test() {
foo()
bar()
val a: Int = <!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>baz()<!>
val b: <!UNRESOLVED_REFERENCE!>T<!> = <!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>baz()<!>
val a: Int = baz()
val b: <!UNRESOLVED_REFERENCE!>T<!> = baz()
}
}
@@ -15101,6 +15101,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt3856.kt")
public void testKt3856() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/kt3856.kt");
doTest(fileName);
}
@TestMetadata("methodsPriority.kt")
public void testMethodsPriority() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/scopes/inheritance/methodsPriority.kt");