Skip to content

Commit cd8b5dc

Browse files
committed
Constructors for inner type aliases: add a failing test (no way to invoke such constructor at the moment).
1 parent 718e8eb commit cd8b5dc

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Pair<X, Y>(val x: X, val y: Y)
2+
3+
class C<T> {
4+
typealias P = Pair<T, T>
5+
typealias P1<X> = Pair<X, T>
6+
typealias P2<Y> = Pair<T, Y>
7+
}
8+
9+
// C<...>.P[<...>]() syntax doesn't work due to the way qualified expressions are resolved now.
10+
// This restriction can be removed later.
11+
val test0 = <!FUNCTION_CALL_EXPECTED!>C<Int><!>.<!UNRESOLVED_REFERENCE!>P<!>(1, 1)
12+
val test1 = <!FUNCTION_CALL_EXPECTED!>C<Int><!>.<!UNRESOLVED_REFERENCE!>P1<!><String>("", 1)
13+
val test2 = <!FUNCTION_CALL_EXPECTED!>C<Int><!>.<!UNRESOLVED_REFERENCE!>P2<!><String>(1, "")
14+
val test3 = <!FUNCTION_CALL_EXPECTED!>C<Int><!>.<!UNRESOLVED_REFERENCE!>P1<!>("", 1)
15+
val test4 = <!FUNCTION_CALL_EXPECTED!>C<Int><!>.<!UNRESOLVED_REFERENCE!>P2<!>(1, "")
16+
17+
// C.P() syntax could work if we add captured type parameters as type variables in a constraint system for corresponding call.
18+
// However, this should be consistent with inner classes capturing type parameters.
19+
val test5 = C.P(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>)
20+
val test6 = C.<!TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>P1<!>("", <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>)
21+
val test7 = C.<!TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>P2<!>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, "")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package
2+
3+
public val test0: [ERROR : Type for C<Int>.P(1, 1)]
4+
public val test1: [ERROR : Type for C<Int>.P1<String>("", 1)]
5+
public val test2: [ERROR : Type for C<Int>.P2<String>(1, "")]
6+
public val test3: [ERROR : Type for C<Int>.P1("", 1)]
7+
public val test4: [ERROR : Type for C<Int>.P2(1, "")]
8+
public val test5: Pair<T, T>
9+
public val test6: Pair<kotlin.String, T>
10+
public val test7: Pair<T, kotlin.String>
11+
12+
public final class C</*0*/ T> {
13+
public constructor C</*0*/ T>()
14+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
15+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
16+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
17+
public typealias P /*captured type parameters: /*0*/ T*/ = Pair<T, T>
18+
public typealias P1</*0*/ X> /*captured type parameters: /*1*/ T*/ = Pair<X, T>
19+
public typealias P2</*0*/ Y> /*captured type parameters: /*1*/ T*/ = Pair<T, Y>
20+
}
21+
22+
public final class Pair</*0*/ X, /*1*/ Y> {
23+
public constructor Pair</*0*/ X, /*1*/ Y>(/*0*/ x: X, /*1*/ y: Y)
24+
public final val x: X
25+
public final val y: Y
26+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
27+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
28+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
29+
}

compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20938,6 +20938,12 @@ public void testInnerTypeAliasAsType2() throws Exception {
2093820938
doTest(fileName);
2093920939
}
2094020940

20941+
@TestMetadata("innerTypeAliasConstructor.kt")
20942+
public void testInnerTypeAliasConstructor() throws Exception {
20943+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt");
20944+
doTest(fileName);
20945+
}
20946+
2094120947
@TestMetadata("isAsWithTypeAlias.kt")
2094220948
public void testIsAsWithTypeAlias() throws Exception {
2094320949
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/isAsWithTypeAlias.kt");

0 commit comments

Comments
 (0)