Fix visibility checks for constructor call based on type alias
Constructor is invisible iff. either underlying constructor or corresposing type alias is invisible #KT-12888 Fixed
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||||
|
// !CHECK_TYPE
|
||||||
|
// FILE: a.kt
|
||||||
|
package a
|
||||||
|
|
||||||
|
class B(x: String)
|
||||||
|
typealias A1 = B
|
||||||
|
private typealias A2 = B
|
||||||
|
private typealias A3 = B
|
||||||
|
|
||||||
|
fun A3(x: Any) = "OK"
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
A3("") checkType { _<B>() }
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
package usage
|
||||||
|
|
||||||
|
import a.B
|
||||||
|
|
||||||
|
fun baz() {
|
||||||
|
a.A1("") // resolved to B constructor, OK
|
||||||
|
a.<!INVISIBLE_MEMBER!>A2<!>("") // resolved to B constructor, INVISIBLE_MEMBER because type alias is private, OK
|
||||||
|
|
||||||
|
a.A3("") checkType { _<String>() }
|
||||||
|
|
||||||
|
val x: a.<!INVISIBLE_REFERENCE!>A2<!> = B("") // A2 is unresolved because it's private in file, OK
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
package a {
|
||||||
|
public typealias A1 = a.B
|
||||||
|
private typealias A2 = a.B
|
||||||
|
private typealias A3 = a.B
|
||||||
|
public fun A3(/*0*/ x: kotlin.Any): kotlin.String
|
||||||
|
public fun bar(): kotlin.Unit
|
||||||
|
|
||||||
|
public final class B {
|
||||||
|
public constructor B(/*0*/ x: kotlin.String)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
package usage {
|
||||||
|
public fun baz(): kotlin.Unit
|
||||||
|
}
|
||||||
@@ -19635,6 +19635,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("constructorCallThroughPrivateAlias.kt")
|
||||||
|
public void testConstructorCallThroughPrivateAlias() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/constructorCallThroughPrivateAlias.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("exposedExpandedType.kt")
|
@TestMetadata("exposedExpandedType.kt")
|
||||||
public void testExposedExpandedType() throws Exception {
|
public void testExposedExpandedType() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/exposedExpandedType.kt");
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.descriptors;
|
|||||||
import kotlin.collections.SetsKt;
|
import kotlin.collections.SetsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.SuperCallReceiverValue;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.SuperCallReceiverValue;
|
||||||
@@ -315,6 +316,14 @@ public class Visibilities {
|
|||||||
}
|
}
|
||||||
parent = DescriptorUtils.getParentOfType(parent, DeclarationDescriptorWithVisibility.class);
|
parent = DescriptorUtils.getParentOfType(parent, DeclarationDescriptorWithVisibility.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (what instanceof TypeAliasConstructorDescriptor) {
|
||||||
|
DeclarationDescriptorWithVisibility invisibleMember =
|
||||||
|
findInvisibleMember(receiver, ((TypeAliasConstructorDescriptor) what).getTypeAliasDescriptor(), from);
|
||||||
|
|
||||||
|
if (invisibleMember != null) return invisibleMember;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user