xref: /aosp_15_r20/external/ksp/test-utils/testData/api/asMemberOf.kt (revision af87fb4bb8e3042070d2a054e912924f599b22b7)
1 /*
2  * Copyright 2022 Google LLC
3  * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 // WITH_RUNTIME
19 // TEST PROCESSOR: AsMemberOfProcessor
20 // EXPECTED:
21 // Child1!!
22 // intType: kotlin.Int!!
23 // baseTypeArg1: kotlin.Int!!
24 // baseTypeArg2: kotlin.String?
25 // typePair: kotlin.Pair!!<kotlin.String?, kotlin.Int!!>
26 // errorType: <Error>?
27 // extensionProperty: kotlin.String?
28 // returnInt: () -> kotlin.Int!!
29 // returnArg1: () -> kotlin.Int!!
30 // returnArg1Nullable: () -> kotlin.Int?
31 // returnArg2: () -> kotlin.String?
32 // returnArg2Nullable: () -> kotlin.String?
33 // receiveArgs: (kotlin.Int?, kotlin.Int!!, kotlin.String?) -> kotlin.Unit!!
34 // receiveArgsPair: (kotlin.Pair!!<kotlin.Int!!, kotlin.String?>, kotlin.Pair?<kotlin.Int?, kotlin.String?>) -> kotlin.Unit!!
35 // functionArgType: <BaseTypeArg1: kotlin.Any?>(Base.functionArgType.BaseTypeArg1?) -> kotlin.String?
36 // functionArgTypeWithBounds: <in T: kotlin.Int!!>(Base.functionArgTypeWithBounds.T?) -> kotlin.String?
37 // extensionFunction: kotlin.Int!!.() -> kotlin.Int?
38 // Child2!!<kotlin.Any?>
39 // intType: kotlin.Int!!
40 // baseTypeArg1: kotlin.Any?
41 // baseTypeArg2: kotlin.Any?
42 // typePair: kotlin.Pair!!<kotlin.Any?, kotlin.Any?>
43 // errorType: <Error>?
44 // extensionProperty: kotlin.Any?
45 // returnInt: () -> kotlin.Int!!
46 // returnArg1: () -> kotlin.Any?
47 // returnArg1Nullable: () -> kotlin.Any?
48 // returnArg2: () -> kotlin.Any?
49 // returnArg2Nullable: () -> kotlin.Any?
50 // receiveArgs: (kotlin.Int?, kotlin.Any?, kotlin.Any?) -> kotlin.Unit!!
51 // receiveArgsPair: (kotlin.Pair!!<kotlin.Any?, kotlin.Any?>, kotlin.Pair?<kotlin.Any?, kotlin.Any?>) -> kotlin.Unit!!
52 // functionArgType: <BaseTypeArg1: kotlin.Any?>(Base.functionArgType.BaseTypeArg1?) -> kotlin.Any?
53 // functionArgTypeWithBounds: <in T: kotlin.Any?>(Base.functionArgTypeWithBounds.T?) -> kotlin.Any?
54 // extensionFunction: kotlin.Any?.() -> kotlin.Any?
55 // Child2!!<kotlin.String!!>
56 // intType: kotlin.Int!!
57 // baseTypeArg1: kotlin.String!!
58 // baseTypeArg2: kotlin.String?
59 // typePair: kotlin.Pair!!<kotlin.String?, kotlin.String!!>
60 // errorType: <Error>?
61 // extensionProperty: kotlin.String?
62 // returnInt: () -> kotlin.Int!!
63 // returnArg1: () -> kotlin.String!!
64 // returnArg1Nullable: () -> kotlin.String?
65 // returnArg2: () -> kotlin.String?
66 // returnArg2Nullable: () -> kotlin.String?
67 // receiveArgs: (kotlin.Int?, kotlin.String!!, kotlin.String?) -> kotlin.Unit!!
68 // receiveArgsPair: (kotlin.Pair!!<kotlin.String!!, kotlin.String?>, kotlin.Pair?<kotlin.String?, kotlin.String?>) -> kotlin.Unit!!
69 // functionArgType: <BaseTypeArg1: kotlin.Any?>(Base.functionArgType.BaseTypeArg1?) -> kotlin.String?
70 // functionArgTypeWithBounds: <in T: kotlin.String!!>(Base.functionArgTypeWithBounds.T?) -> kotlin.String?
71 // extensionFunction: kotlin.String!!.() -> kotlin.String?
72 // NotAChild!!
73 // intType: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `intType` (Base)
74 // baseTypeArg1: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `baseTypeArg1` (Base)
75 // baseTypeArg2: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `baseTypeArg2` (Base)
76 // typePair: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `typePair` (Base)
77 // errorType: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `errorType` (Base)
78 // extensionProperty: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `extensionProperty` (Base)
79 // returnInt: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnInt` (Base)
80 // returnArg1: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnArg1` (Base)
81 // returnArg1Nullable: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnArg1Nullable` (Base)
82 // returnArg2: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnArg2` (Base)
83 // returnArg2Nullable: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnArg2Nullable` (Base)
84 // receiveArgs: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `receiveArgs` (Base)
85 // receiveArgsPair: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `receiveArgsPair` (Base)
86 // functionArgType: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `functionArgType` (Base)
87 // functionArgTypeWithBounds: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `functionArgTypeWithBounds` (Base)
88 // extensionFunction: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `extensionFunction` (Base)
89 // List#get
90 // listOfStrings: (kotlin.Int!!) -> kotlin.String!!
91 // setOfStrings: java.lang.IllegalArgumentException: Set<String> is not a sub type of the class/interface that contains `get` (List)
92 // Set#contains
93 // listOfStrings: java.lang.IllegalArgumentException: List<String> is not a sub type of the class/interface that contains `contains` (Set)
94 // setOfStrings: (kotlin.String!!) -> kotlin.Boolean!!
95 // JavaChild1!!
96 // intType: kotlin.Int!!
97 // typeArg1: kotlin.String
98 // typeArg2: kotlin.Int
99 // errorType: <Error>?
100 // returnArg1: () -> kotlin.Int
101 // receiveArgs: (kotlin.String, kotlin.Int, kotlin.Int!!) -> kotlin.Unit!!
102 // methodArgType: <BaseTypeArg1: kotlin.Any>(JavaBase.methodArgType.BaseTypeArg1, kotlin.Int) -> kotlin.Unit!!
103 // methodArgTypeWithBounds: <T: kotlin.String>(JavaBase.methodArgTypeWithBounds.T) -> kotlin.Unit!!
104 // fileLevelFunction: java.lang.IllegalArgumentException: Cannot call asMemberOf with a function that is not declared in a class or an interface
105 // fileLevelExtensionFunction: java.lang.IllegalArgumentException: Cannot call asMemberOf with a function that is not declared in a class or an interface
106 // fileLevelProperty: java.lang.IllegalArgumentException: Cannot call asMemberOf with a property that is not declared in a class or an interface
107 // errorType: (<Error>?) -> <Error>?
108 // expected comparison failures
109 // <BaseTypeArg1: kotlin.Any?>(Base.functionArgType.BaseTypeArg1?) -> kotlin.String?
110 // () -> kotlin.Int!!
111 // () -> kotlin.Int!!
112 // (kotlin.Int!!) -> kotlin.Unit!!
113 // END
114 // FILE: Input.kt
115 open class Base<BaseTypeArg1, BaseTypeArg2> {
116     val intType: Int = 0
117     val baseTypeArg1: BaseTypeArg1 = TODO()
118     val baseTypeArg2: BaseTypeArg2 = TODO()
119     val typePair: Pair<BaseTypeArg2, BaseTypeArg1>  = TODO()
120     val errorType: NonExistType = TODO()
returnIntnull121     fun returnInt():Int = TODO()
122     fun returnArg1(): BaseTypeArg1 = TODO()
123     fun returnArg1Nullable(): BaseTypeArg1? = TODO()
124     fun returnArg2(): BaseTypeArg2 = TODO()
125     fun returnArg2Nullable(): BaseTypeArg2? = TODO()
126     fun receiveArgs(intArg:Int?, arg1: BaseTypeArg1, arg2:BaseTypeArg2):Unit = TODO()
127     fun receiveArgsPair(
128         pairs: Pair<BaseTypeArg1, BaseTypeArg2>,
129         pairNullable: Pair<BaseTypeArg1?, BaseTypeArg2?>?,
130     ):Unit = TODO()
131     // intentional type argument name conflict here to ensure it does not get replaced by mistake
132     fun <BaseTypeArg1> functionArgType(t:BaseTypeArg1?): BaseTypeArg2 = TODO()
133     fun <in T: BaseTypeArg1> functionArgTypeWithBounds(t:T?): BaseTypeArg2 = TODO()
134     fun BaseTypeArg1.extensionFunction():BaseTypeArg1? = TODO()
135     val BaseTypeArg2.extensionProperty:BaseTypeArg2? = TODO()
136 }
137 
138 open class Child1 : Base<Int, String?>() {
139 }
140 
141 open class Child2<ChildTypeArg1> : Base<ChildTypeArg1, ChildTypeArg1?>() {
142 }
143 
144 class NotAChild
145 val child2WithString: Child2<String> = TODO()
146 val listOfStrings: List<String> = TODO()
147 val setOfStrings: Set<String> = TODO()
148 
fileLevelExtensionFunctionnull149 fun <T>List<T>.fileLevelExtensionFunction():Unit = TODO()
150 fun <T>fileLevelFunction():Unit = TODO()
151 val fileLevelProperty:Int = 3
152 val errorType: NonExistingType
153 
154 interface KotlinInterface {
155     val x:Int
156     var y:Int
157 }
158 
159 // FILE: JavaInput.java
160 class JavaBase<BaseTypeArg1, BaseTypeArg2> {
161     int intType;
162     BaseTypeArg1 typeArg1;
163     BaseTypeArg2 typeArg2;
164     NonExist errorType;
165     BaseTypeArg2 returnArg1() {
166         return null;
167     }
168     void receiveArgs(BaseTypeArg1 arg1, BaseTypeArg2 arg2, int intArg) {
169     }
170     <BaseTypeArg1> void methodArgType(BaseTypeArg1 arg1, BaseTypeArg2 arg2) {
171     }
172     <T extends BaseTypeArg1> void methodArgTypeWithBounds(T arg1) {
173     }
174 }
175 
176 class JavaChild1 extends JavaBase<String, Integer> {
177 }
178 
179 class JavaImpl implements KotlinInterface {
<lambda>null180     public int getX() {
181         return 1;
182     }
<lambda>null183     public int getY() {
184         return 1;
185     }
186     public void setY(int value) {
187     }
188 }
189