Refine diagnostic about type arguments for an outer class
#KT-11263 Fixed
This commit is contained in:
@@ -103,6 +103,7 @@ public interface Errors {
|
||||
DiagnosticFactory2<KtTypeReference, KotlinType, KotlinType> UPPER_BOUND_VIOLATED = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory0<KtNullableType> REDUNDANT_NULLABLE = DiagnosticFactory0.create(WARNING, NULLABLE_TYPE);
|
||||
DiagnosticFactory2<KtElement, Integer, DeclarationDescriptor> WRONG_NUMBER_OF_TYPE_ARGUMENTS = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory1<KtElement, ClassDescriptor> OUTER_CLASS_ARGUMENTS_REQUIRED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtElement, String> TYPE_ARGUMENTS_NOT_ALLOWED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtTypeReference, Integer, String> NO_TYPE_ARGUMENTS_ON_RHS = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory1<KtTypeProjection, ClassifierDescriptor> CONFLICTING_PROJECTION = DiagnosticFactory1.create(ERROR, VARIANCE_IN_PROJECTION);
|
||||
|
||||
+5
@@ -680,6 +680,11 @@ public class DefaultErrorMessages {
|
||||
|
||||
String wrongNumberOfTypeArguments = "{0,choice,0#No type arguments|1#One type argument|1<{0,number,integer} type arguments} expected";
|
||||
MAP.put(WRONG_NUMBER_OF_TYPE_ARGUMENTS, wrongNumberOfTypeArguments + " for {1}", null, WITHOUT_MODIFIERS);
|
||||
|
||||
MAP.put(
|
||||
OUTER_CLASS_ARGUMENTS_REQUIRED,
|
||||
"Type arguments should be specified for an outer {0}. Use full class name to specify them",
|
||||
RENDER_CLASS_OR_OBJECT_NAME);
|
||||
MAP.put(NO_TYPE_ARGUMENTS_ON_RHS, wrongNumberOfTypeArguments + ". Use ''{1}'' if you don''t want to pass type arguments", null, STRING);
|
||||
MAP.put(TYPE_ARGUMENTS_NOT_ALLOWED, "Type arguments are not allowed {0}", STRING);
|
||||
|
||||
|
||||
@@ -645,8 +645,7 @@ class TypeResolver(
|
||||
|
||||
if (restArguments == null && typeArgumentsCanBeSpecifiedCount > result.size) {
|
||||
c.trace.report(
|
||||
WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(
|
||||
qualifierParts.last().expression, typeArgumentsCanBeSpecifiedCount, classifierDescriptor))
|
||||
OUTER_CLASS_ARGUMENTS_REQUIRED.on(qualifierParts.first().expression, nextParameterOwner))
|
||||
return null
|
||||
}
|
||||
else if (restArguments == null) {
|
||||
|
||||
Vendored
+1
-1
@@ -14,7 +14,7 @@ class A {
|
||||
|
||||
// Does not work, could be Outer<String>.Inner<Int>
|
||||
// TODO: Should work?
|
||||
fun foo(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inner<!><Int>) {
|
||||
fun foo(x: <!OUTER_CLASS_ARGUMENTS_REQUIRED!>Inner<!><Int>) {
|
||||
// Inner<Char>() call use companion as implicit receiver
|
||||
val y: Outer<String>.Inner<Char> = Inner<Char>()
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -2,6 +2,6 @@ interface Inv<X>
|
||||
class Outer<E> {
|
||||
inner class Inner
|
||||
|
||||
class Nested : Inv<<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inner<!>>
|
||||
object Obj : Inv<<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inner<!>>
|
||||
class Nested : Inv<<!OUTER_CLASS_ARGUMENTS_REQUIRED!>Inner<!>>
|
||||
object Obj : Inv<<!OUTER_CLASS_ARGUMENTS_REQUIRED!>Inner<!>>
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ class Outer<E> {
|
||||
}
|
||||
|
||||
class Nested {
|
||||
fun bar(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inner<!>) {}
|
||||
fun bar(x: <!OUTER_CLASS_ARGUMENTS_REQUIRED(class 'Outer')!>Inner<!>) {}
|
||||
}
|
||||
}
|
||||
|
||||
class E
|
||||
|
||||
fun bar(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Inner<!>) {}
|
||||
fun bar(x: <!OUTER_CLASS_ARGUMENTS_REQUIRED(class 'Outer')!>Inner<!>) {}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import A.B.D
|
||||
import A.B.C
|
||||
import A.B.D.Innermost
|
||||
|
||||
class A<T> {
|
||||
inner class B<F> {
|
||||
inner class C<E>
|
||||
inner class D {
|
||||
inner class Innermost<X>
|
||||
}
|
||||
}
|
||||
|
||||
class Nested {
|
||||
val x: <!OUTER_CLASS_ARGUMENTS_REQUIRED(class 'A')!>B<!><String>? = null
|
||||
val y: <!OUTER_CLASS_ARGUMENTS_REQUIRED(class 'A')!>B<!><String>.C<String>? = null
|
||||
val z: <!OUTER_CLASS_ARGUMENTS_REQUIRED(class 'A')!>B<!><String>.D? = null
|
||||
|
||||
val c: <!OUTER_CLASS_ARGUMENTS_REQUIRED(class 'B')!>C<!><Int>? = null
|
||||
val d: <!OUTER_CLASS_ARGUMENTS_REQUIRED(class 'B')!>D<!>? = null
|
||||
|
||||
val innerMost: <!OUTER_CLASS_ARGUMENTS_REQUIRED(class 'B')!>Innermost<!><String>? = null
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package
|
||||
|
||||
public final class A</*0*/ T> {
|
||||
public constructor A</*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 inner class B</*0*/ F> /*captured type parameters: /*1*/ T*/ {
|
||||
public constructor B</*0*/ F>()
|
||||
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 inner class C</*0*/ E> /*captured type parameters: /*1*/ F, /*2*/ T*/ {
|
||||
public constructor C</*0*/ E>()
|
||||
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 inner class D /*captured type parameters: /*0*/ F, /*1*/ T*/ {
|
||||
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
|
||||
|
||||
public final inner class Innermost</*0*/ X> /*captured type parameters: /*1*/ F, /*2*/ T*/ {
|
||||
public constructor Innermost</*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 Nested {
|
||||
public constructor Nested()
|
||||
public final val c: [ERROR : C]<kotlin.Int>?
|
||||
public final val d: [ERROR : D]?
|
||||
public final val innerMost: [ERROR : Innermost]<kotlin.String>?
|
||||
public final val x: [ERROR : B]<kotlin.String>?
|
||||
public final val y: [ERROR : C]<kotlin.String, kotlin.String>?
|
||||
public final val z: [ERROR : D]<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
|
||||
}
|
||||
}
|
||||
@@ -7934,6 +7934,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("outerArgumentsRequired.kt")
|
||||
public void testOuterArgumentsRequired() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/innerClasses/outerArgumentsRequired.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("parameterShadowing.kt")
|
||||
public void testParameterShadowing() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/innerClasses/parameterShadowing.kt");
|
||||
|
||||
Reference in New Issue
Block a user