Forbid Foo<T>.Bar
This commit is contained in:
@@ -176,6 +176,8 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<PsiElement> NO_GENERICS_IN_SUPERTYPE_SPECIFIER = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<JetTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetTypeReference> SUPERTYPE_APPEARS_TWICE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory3<JetDelegationSpecifierList, TypeParameterDescriptor, ClassDescriptor, Collection<JetType>>
|
||||
|
||||
+1
-1
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.renderer.MultiRenderer;
|
||||
import org.jetbrains.kotlin.renderer.Renderer;
|
||||
import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker.VarianceConflictDiagnosticData;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.kotlin.util.MappedExtensionProvider;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
@@ -341,6 +340,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION, "Type parameter ''{0}'' is not an expression", NAME);
|
||||
MAP.put(TYPE_PARAMETER_ON_LHS_OF_DOT, "Type parameter ''{0}'' cannot have or inherit a companion object, so it cannot be on the left hand side of dot", NAME);
|
||||
MAP.put(NO_GENERICS_IN_SUPERTYPE_SPECIFIER, "Generic arguments of the base type must be specified");
|
||||
MAP.put(GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED, "Generic arguments in containing types are not allowed");
|
||||
MAP.put(NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE, "Nested {0} accessed via instance reference", RENDER_CLASS_OR_OBJECT_NAME);
|
||||
MAP.put(NESTED_CLASS_SHOULD_BE_QUALIFIED, "Nested {0} should be qualified as ''{1}''", RENDER_CLASS_OR_OBJECT_NAME, TO_STRING);
|
||||
|
||||
|
||||
@@ -82,6 +82,15 @@ public class JetUserType extends JetElementImplStub<KotlinUserTypeStub> implemen
|
||||
return getStubOrPsiChild(JetStubElementTypes.USER_TYPE);
|
||||
}
|
||||
|
||||
public boolean hasTypesWithTypeArgsInside() {
|
||||
for (JetUserType type : getStubOrPsiChildrenAsList(JetStubElementTypes.USER_TYPE)) {
|
||||
if (!type.getTypeArguments().isEmpty() || type.hasTypesWithTypeArgsInside()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void deleteQualifier() {
|
||||
JetUserType qualifier = getQualifier();
|
||||
assert qualifier != null;
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.debugTypeInfo
|
||||
@@ -137,6 +138,10 @@ public class TypeResolver(
|
||||
|
||||
c.trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor)
|
||||
|
||||
if (type.hasTypesWithTypeArgsInside()) {
|
||||
c.trace.report(Errors.GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED.on(type))
|
||||
}
|
||||
|
||||
when (classifierDescriptor) {
|
||||
is TypeParameterDescriptor -> {
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
class Derived(): funNestedStaticGenericClass<String>.Inner<String>() {
|
||||
class Derived(): funNestedStaticGenericClass.Inner<String>() {
|
||||
fun test(): String {
|
||||
return funNestedStaticGenericClass.Inner.protectedFun()!!
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ val n1 = A.Nested::class
|
||||
val n2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>A.Nested<*>::class<!>
|
||||
|
||||
val i1 = A.Inner::class
|
||||
val i2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>A<*>.Inner<*>::class<!>
|
||||
val i3 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>A<Int>.Inner<CharSequence>::class<!>
|
||||
val i2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!><!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED!>A<*>.Inner<*><!>::class<!>
|
||||
val i3 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!><!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED!>A<Int>.Inner<CharSequence><!>::class<!>
|
||||
|
||||
val m1 = Map::class
|
||||
val m2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Map<Int, *>::class<!>
|
||||
val m3 = Map.Entry::class
|
||||
|
||||
val b1 = Int::class
|
||||
val b2 = Nothing::class
|
||||
val b2 = Nothing::class
|
||||
@@ -0,0 +1,36 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
|
||||
class Foo<T> {
|
||||
class Bar<X> {
|
||||
class Baz {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> a() {}
|
||||
|
||||
fun test() {
|
||||
Foo::class
|
||||
Foo.Bar::class
|
||||
Foo.Bar.Baz::class
|
||||
|
||||
a<Foo.Bar<String>>()
|
||||
a<Foo.Bar.Baz>()
|
||||
|
||||
<!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED!>Foo<String>.Bar<!>::class
|
||||
<!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED!>Foo<<!DEBUG_INFO_MISSING_UNRESOLVED!>String<!>>.Bar.Baz<!>::class
|
||||
|
||||
a<<!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED, WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Foo<String>.Bar<!>>()
|
||||
a<<!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED!>Foo<<!DEBUG_INFO_MISSING_UNRESOLVED!>String<!>>.Bar.Baz<!>>()
|
||||
|
||||
a<Foo.Bar<Int>>()
|
||||
a<<!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED!>Foo.Bar<Int>.Baz<!>>()
|
||||
}
|
||||
|
||||
fun <T: Foo<String.<!UNRESOLVED_REFERENCE!>Bar<!>>> x() {}
|
||||
fun <!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED, WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Foo<String>.Bar<!>.ext() {}
|
||||
|
||||
fun ex1(<!UNUSED_PARAMETER!>a<!>: <!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED!>Foo<String>.Bar<String><!>): <!GENERICS_IN_CONTAINING_TYPE_NOT_ALLOWED!>Foo<String>.Bar<String><!> {
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> a(): kotlin.Unit
|
||||
public fun ex1(/*0*/ a: Foo.Bar<kotlin.String>): Foo.Bar<kotlin.String>
|
||||
public fun test(): kotlin.Unit
|
||||
public fun </*0*/ T : Foo<[ERROR : String.Bar]>> x(): kotlin.Unit
|
||||
public fun [ERROR : Bar].ext(): kotlin.Unit
|
||||
|
||||
public final class Foo</*0*/ T> {
|
||||
public constructor Foo</*0*/ T>()
|
||||
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 Bar</*0*/ X> {
|
||||
public constructor Bar</*0*/ X>()
|
||||
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 Baz {
|
||||
public constructor Baz()
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -30,7 +30,7 @@ fun test(ab_c: c) {
|
||||
ab_c3.ab_c()
|
||||
}
|
||||
|
||||
fun test2(a_bc: a.b<Int>.c) {
|
||||
fun test2(a_bc: a.b.c) {
|
||||
a_bc.<!UNRESOLVED_REFERENCE!>a_bc<!>() // todo
|
||||
a_bc.ab_c() // todo
|
||||
}
|
||||
@@ -69,7 +69,7 @@ fun test(a_b: b) {
|
||||
_ab2.<!UNRESOLVED_REFERENCE!>_ab<!>() // todo
|
||||
}
|
||||
|
||||
fun test2(_ab: a<Int>.b) {
|
||||
fun test2(_ab: a.b) {
|
||||
_ab._ab()
|
||||
_ab.<!UNRESOLVED_REFERENCE!>a_b<!>()
|
||||
}
|
||||
@@ -6,7 +6,7 @@ class A<TA> {
|
||||
inner class D<TD> {
|
||||
fun <P1, P2, P3, P4> foo(p1: P1, p2: P2, p3: P3, p4: P4): Nothing = null!!
|
||||
|
||||
fun bar(ta: TA, tb: TB, tc: TC, td: TD): A<TA>.B<TB>.C<TC>.D<TD> = foo<TA, TB, TC, TD>(ta, tb, tc, td)
|
||||
fun bar(ta: TA, tb: TB, tc: TC, td: TD): A.B.C.D<TD> = foo<TA, TB, TC, TD>(ta, tb, tc, td)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6327,6 +6327,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("genericsInType.kt")
|
||||
public void testGenericsInType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/genericsInType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt1575-Class.kt")
|
||||
public void testKt1575_Class() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/kt1575-Class.kt");
|
||||
|
||||
Reference in New Issue
Block a user