File tree Expand file tree Collapse file tree 17 files changed +133
-37
lines changed
resolution/src/org/jetbrains/kotlin/resolve/calls/tower
testData/diagnostics/tests
tests/org/jetbrains/kotlin/checkers Expand file tree Collapse file tree 17 files changed +133
-37
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ enum class WrongResolutionToClassifier(val message: (Name) -> String) {
31
31
INTERFACE_AS_VALUE ({ " Interface $it does not have companion object" }),
32
32
INTERFACE_AS_FUNCTION ({ " Interface $it does not have constructors" }),
33
33
CLASS_AS_VALUE ({ " Class $it does not have companion object" }),
34
+ INNER_CLASS_CONSTRUCTOR_NO_RECEIVER ({ " Constructor of inner class $it can be called only with receiver of containing class" }),
34
35
OBJECT_AS_FUNCTION ({ " Function 'invoke()' is not found in object $it " })
35
36
}
36
37
@@ -92,7 +93,11 @@ private fun ErrorCandidateContext.asClassifierCall(asFunction: Boolean) {
92
93
when (classifier.kind) {
93
94
ClassKind .INTERFACE -> if (asFunction) INTERFACE_AS_FUNCTION else INTERFACE_AS_VALUE
94
95
ClassKind .OBJECT -> if (asFunction) OBJECT_AS_FUNCTION else return
95
- ClassKind .CLASS -> if (asFunction) return else CLASS_AS_VALUE
96
+ ClassKind .CLASS -> when {
97
+ asFunction && explicitReceiver is QualifierReceiver ? && classifier.isInner -> INNER_CLASS_CONSTRUCTOR_NO_RECEIVER
98
+ ! asFunction -> CLASS_AS_VALUE
99
+ else -> return
100
+ }
96
101
else -> return
97
102
}
98
103
}
Original file line number Diff line number Diff line change @@ -41,8 +41,8 @@ fun f() {
41
41
C .O
42
42
C .O .InO
43
43
C .A ()
44
- C .< ! UNRESOLVED_REFERENCE ! > B < ! > ()
44
+ C .< ! RESOLUTION_TO_CLASSIFIER ! > B < ! > ()
45
45
46
46
C .E3 .< ! UNRESOLVED_REFERENCE ! > O_O < ! >
47
47
C .E3 .< ! UNRESOLVED_REFERENCE ! > G < ! > ()
48
- }
48
+ }
Original file line number Diff line number Diff line change 1
1
class Outer1 {
2
2
class Nested
3
-
3
+
4
4
class C1 { val b = Nested () }
5
5
class C2 (val b : Any = Nested ())
6
6
inner class C3 { val b = Nested () }
7
7
inner class C4 (val b : Any = Nested ())
8
-
8
+
9
9
inner class Inner
10
-
11
- class C5 { val b = < ! UNRESOLVED_REFERENCE ! > Inner < ! > () }
12
- class C6 (val b : Any = <!UNRESOLVED_REFERENCE !>Inner <!>())
10
+
11
+ class C5 { val b = < ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > () }
12
+ class C6 (val b : Any = <!RESOLUTION_TO_CLASSIFIER !>Inner <!>())
13
13
inner class C7 { val b = Inner () }
14
14
inner class C8 (val b : Any = Inner ())
15
15
}
@@ -18,15 +18,15 @@ class Outer1 {
18
18
class Outer2 {
19
19
class Nested {
20
20
fun foo () = Outer2 ()
21
- fun bar () = < ! UNRESOLVED_REFERENCE ! > Inner < ! > ()
21
+ fun bar () = < ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > ()
22
22
}
23
23
inner class Inner {
24
24
fun foo () = Outer2 ()
25
25
fun bar () = Nested ()
26
26
}
27
-
27
+
28
28
fun foo () {
29
29
Nested ()
30
30
Inner ()
31
31
}
32
- }
32
+ }
Original file line number Diff line number Diff line change
1
+ // !DIAGNOSTICS: -UNUSED_PARAMETER
2
+ // SKIP_TXT
3
+ // FILE: Outer.kt
4
+ package abc
5
+ class Outer {
6
+ inner class Inner () {
7
+ constructor (x: Int ) : this () {}
8
+ }
9
+
10
+ companion object {
11
+
12
+ fun baz () {
13
+ < ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > ()
14
+ < ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > (1 )
15
+ }
16
+ }
17
+ }
18
+
19
+ fun foo () {
20
+ Outer .< ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > ()
21
+ Outer .< ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > (1 )
22
+ }
23
+
24
+ // FILE: imported.kt
25
+ import abc.Outer
26
+ import abc.Outer.Inner
27
+
28
+ fun bar () {
29
+ < ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > ()
30
+ < ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > (1 )
31
+
32
+ with (Outer ()) {
33
+ Inner ()
34
+ Inner (1 )
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ // !DIAGNOSTICS: -UNUSED_PARAMETER
2
+ // SKIP_TXT
3
+ // FILE: Outer.kt
4
+ package abc
5
+ class Outer {
6
+ inner class Inner () {
7
+ constructor (x: Int ) : this () {}
8
+ }
9
+
10
+ companion object {
11
+ fun Inner (x : String ) {}
12
+
13
+ fun baz () {
14
+ // Diagnostic here could be better (why can't I call the constructor above?)
15
+ Inner (< ! NO_VALUE_FOR_PARAMETER ! > )< ! >
16
+ Inner (< ! CONSTANT_EXPECTED_TYPE_MISMATCH ! > 1 < ! > )
17
+ Inner (" " )
18
+ }
19
+ }
20
+ }
21
+
22
+ fun foo () {
23
+ Outer .Inner (< ! NO_VALUE_FOR_PARAMETER ! > )< ! >
24
+ Outer .Inner (< ! CONSTANT_EXPECTED_TYPE_MISMATCH ! > 1 < ! > )
25
+ Outer .Inner (" " )
26
+ }
27
+
28
+ // FILE: imported.kt
29
+ import abc.Outer
30
+ import abc.Outer.Inner
31
+ import abc.Outer.Companion.Inner
32
+
33
+ fun bar () {
34
+ Inner (< ! NO_VALUE_FOR_PARAMETER ! > )< ! >
35
+ Inner (< ! CONSTANT_EXPECTED_TYPE_MISMATCH ! > 1 < ! > )
36
+ Inner (" " )
37
+
38
+ with (Outer ()) {
39
+ Inner ()
40
+ Inner (1 )
41
+ Inner (" " )
42
+ }
43
+ }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class Test {
10
10
}
11
11
12
12
fun more (): InnerClass {
13
- val b = < ! UNRESOLVED_REFERENCE ! > InnerClass < ! > ()
13
+ val b = < ! RESOLUTION_TO_CLASSIFIER ! > InnerClass < ! > ()
14
14
15
15
val < ! UNUSED_VARIABLE ! > testVal< ! > = < ! UNRESOLVED_REFERENCE ! > inClass< ! >
16
16
< ! UNRESOLVED_REFERENCE ! > foo< ! > ()
@@ -23,4 +23,4 @@ class Test {
23
23
fun foo () {}
24
24
25
25
open inner class InnerClass
26
- }
26
+ }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class Test {
10
10
}
11
11
12
12
fun more (): InnerClass {
13
- val b = < ! UNRESOLVED_REFERENCE ! > InnerClass < ! > ()
13
+ val b = < ! RESOLUTION_TO_CLASSIFIER ! > InnerClass < ! > ()
14
14
15
15
val < ! UNUSED_VARIABLE ! > testVal< ! > = < ! UNRESOLVED_REFERENCE ! > inClass< ! >
16
16
< ! UNRESOLVED_REFERENCE ! > foo< ! > ()
@@ -24,4 +24,4 @@ class Test {
24
24
}
25
25
26
26
open inner class InnerClass
27
- }
27
+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ class Outer {
2
2
class Nested {
3
3
class NestedNested
4
4
}
5
-
5
+
6
6
inner class Inner {
7
7
inner class InnerInner
8
8
}
@@ -11,7 +11,7 @@ class Outer {
11
11
fun f1 () = Outer ()
12
12
fun f2 () = Outer .Nested ()
13
13
fun f3 () = Outer .Nested .NestedNested ()
14
- fun f4 () = Outer .< ! UNRESOLVED_REFERENCE ! > Inner < ! > ()
15
- fun f5 () = Outer .Inner .< ! UNRESOLVED_REFERENCE ! > InnerInner < ! > ()
14
+ fun f4 () = Outer .< ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > ()
15
+ fun f5 () = Outer .Inner .< ! RESOLUTION_TO_CLASSIFIER ! > InnerInner < ! > ()
16
16
fun f6 () = Outer ().Inner ()
17
- fun f7 () = Outer ().Inner ().InnerInner ()
17
+ fun f7 () = Outer ().Inner ().InnerInner ()
Original file line number Diff line number Diff line change @@ -12,5 +12,5 @@ class C {
12
12
13
13
fun f () {
14
14
< ! RESOLUTION_TO_CLASSIFIER ! > TestInterface < ! > ()
15
- C .< ! UNRESOLVED_REFERENCE ! > I < ! > ()
16
- }
15
+ C .< ! RESOLUTION_TO_CLASSIFIER ! > I < ! > ()
16
+ }
Original file line number Diff line number Diff line change 4
4
n : Nested = foo(),
5
5
n2 : Nested = Nested (),
6
6
inn : Inner = null !!,
7
- inn2 : Inner = <!UNRESOLVED_REFERENCE !>Inner <!>(),
7
+ inn2 : Inner = <!RESOLUTION_TO_CLASSIFIER !>Inner <!>(),
8
8
i : Interface = null !!,
9
9
c : Int = CONST ,
10
10
cc : Int = Companion .CONST ,
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ open class S(
17
17
class A : I by S (
18
18
foo(),
19
19
Nested (),
20
- <!UNRESOLVED_REFERENCE !>Inner <!>(),
20
+ <!RESOLUTION_TO_CLASSIFIER !>Inner <!>(),
21
21
CONST ,
22
22
Companion .CONST ,
23
23
Nested .CONST ,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ open class S(
15
15
class A : S (
16
16
foo(),
17
17
Nested (),
18
- <!UNRESOLVED_REFERENCE !>Inner <!>(),
18
+ <!RESOLUTION_TO_CLASSIFIER !>Inner <!>(),
19
19
CONST ,
20
20
Companion .CONST ,
21
21
Nested .CONST ,
Original file line number Diff line number Diff line change @@ -33,10 +33,10 @@ class E: A() {
33
33
34
34
object Z {
35
35
init {
36
- < ! UNRESOLVED_REFERENCE ! > B < ! > ().< ! DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE ! > foo< ! > ()
37
- < ! UNRESOLVED_REFERENCE ! > B < ! > ().< ! DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE ! > bar< ! > ()
36
+ < ! RESOLUTION_TO_CLASSIFIER ! > B < ! > ().< ! DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE ! > foo< ! > ()
37
+ < ! RESOLUTION_TO_CLASSIFIER ! > B < ! > ().< ! DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE ! > bar< ! > ()
38
38
39
- < ! UNRESOLVED_REFERENCE ! > D < ! > ()
39
+ < ! RESOLUTION_TO_CLASSIFIER ! > D < ! > ()
40
40
C ()
41
41
}
42
42
}
@@ -58,7 +58,7 @@ class F: A() {
58
58
companion object {
59
59
init {
60
60
B ().fas()
61
- < ! UNRESOLVED_REFERENCE ! > D < ! > ().< ! DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE ! > f< ! > ()
61
+ < ! RESOLUTION_TO_CLASSIFIER ! > D < ! > ().< ! DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE ! > f< ! > ()
62
62
}
63
63
}
64
- }
64
+ }
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ class Y: B() {
46
46
47
47
init {
48
48
B_ ()
49
- B .< ! UNRESOLVED_REFERENCE ! > B_ < ! > ()
49
+ B .< ! RESOLUTION_TO_CLASSIFIER ! > B_ < ! > ()
50
50
Y .< ! UNRESOLVED_REFERENCE ! > B_ < ! > ()
51
51
52
52
B_S ()
@@ -59,7 +59,7 @@ class Y: B() {
59
59
val b_s: B_S = null !!
60
60
61
61
init {
62
- < ! UNRESOLVED_REFERENCE ! > B_ < ! > ()
62
+ < ! RESOLUTION_TO_CLASSIFIER ! > B_ < ! > ()
63
63
B_S ()
64
64
}
65
65
}
@@ -83,8 +83,8 @@ class Z: C() {
83
83
84
84
init {
85
85
< ! UNRESOLVED_REFERENCE ! > A_S < ! > ()
86
- < ! UNRESOLVED_REFERENCE ! > B_ < ! > ()
86
+ < ! RESOLUTION_TO_CLASSIFIER ! > B_ < ! > ()
87
87
B_S ()
88
88
}
89
89
}
90
- }
90
+ }
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public class F extends D {
36
36
class X : D () {
37
37
init {
38
38
B_ ()
39
- B .< ! UNRESOLVED_REFERENCE ! > B_ < ! > ()
39
+ B .< ! RESOLUTION_TO_CLASSIFIER ! > B_ < ! > ()
40
40
C .< ! UNRESOLVED_REFERENCE ! > B_ < ! > ()
41
41
D .< ! UNRESOLVED_REFERENCE ! > B_ < ! > ()
42
42
X .< ! UNRESOLVED_REFERENCE ! > B_ < ! > ()
@@ -79,4 +79,4 @@ class Y: F() {
79
79
F .< ! UNRESOLVED_REFERENCE ! > E_S < ! > ()
80
80
Y .< ! UNRESOLVED_REFERENCE ! > E_S < ! > ()
81
81
}
82
- }
82
+ }
Original file line number Diff line number Diff line change @@ -27,8 +27,8 @@ class Outer {
27
27
typealias Test5 = Outer .Inner
28
28
29
29
val test5 = < ! UNRESOLVED_REFERENCE ! > Test5 < ! > ()
30
- val test5a = Outer .< ! UNRESOLVED_REFERENCE ! > Inner < ! > ()
30
+ val test5a = Outer .< ! RESOLUTION_TO_CLASSIFIER ! > Inner < ! > ()
31
31
val test5b = Outer .< ! UNRESOLVED_REFERENCE ! > TestInner < ! > ()
32
32
val test5c = Outer ().< ! UNRESOLVED_REFERENCE ! > TestInner < ! > ()
33
33
val test5d = Outer ().Inner ()
34
- val test5e = Outer ().Test5 ()
34
+ val test5e = Outer ().Test5 ()
Original file line number Diff line number Diff line change @@ -11347,6 +11347,18 @@ public void testInnerClassesInStaticParameters() throws Exception {
11347
11347
doTest(fileName);
11348
11348
}
11349
11349
11350
+ @TestMetadata("innerConstructorsFromQualifiers.kt")
11351
+ public void testInnerConstructorsFromQualifiers() throws Exception {
11352
+ String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt");
11353
+ doTest(fileName);
11354
+ }
11355
+
11356
+ @TestMetadata("innerConstructorsFromQualifiersWithIrrelevantCandidate.kt")
11357
+ public void testInnerConstructorsFromQualifiersWithIrrelevantCandidate() throws Exception {
11358
+ String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiersWithIrrelevantCandidate.kt");
11359
+ doTest(fileName);
11360
+ }
11361
+
11350
11362
@TestMetadata("innerErrorForClassObjects.kt")
11351
11363
public void testInnerErrorForClassObjects() throws Exception {
11352
11364
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inner/innerErrorForClassObjects.kt");
You can’t perform that action at this time.
0 commit comments