@@ -102,6 +102,178 @@ struct JNINestedTypesTests {
102102 )
103103 }
104104
105+ @Test ( " Import: shadowed nested type name " )
106+ func shadowedNestedTypeName_java( ) throws {
107+ // A nested type whose name shadows a type of the same name in an outer
108+ // scope must resolve to the innermost declaration.
109+ try assertOutput (
110+ input: """
111+ public struct Outer {
112+ public enum Kind {
113+ case alpha
114+ case beta
115+ }
116+
117+ public struct Inner {
118+ public enum Kind {
119+ case one
120+ case two
121+ }
122+
123+ public var kind: Kind // Outer.Inner.Kind
124+ }
125+
126+ public var kind: Kind // Outer.Kind
127+ public var inner: Inner
128+ }
129+ """ ,
130+ . jni,
131+ . java,
132+ detectChunkByInitialLines: 1 ,
133+ expectedChunks: [
134+ // The `Inner.kind` property must reference `Outer.Inner.Kind`, not `Outer.Kind`.
135+ """
136+ public Outer.Inner.Kind getKind(SwiftArena swiftArena) {
137+ return Outer.Inner.Kind.wrapMemoryAddressUnsafe(Outer.Inner.$getKind(this.$memoryAddress()), swiftArena);
138+ """ ,
139+ """
140+ public void setKind(Outer.Inner.Kind newValue) {
141+ Outer.Inner.$setKind(newValue.$memoryAddress(), this.$memoryAddress());
142+ """ ,
143+ // The outer `kind` must reference `Outer.Kind`.
144+ """
145+ public Outer.Kind getKind(SwiftArena swiftArena) {
146+ return Outer.Kind.wrapMemoryAddressUnsafe(Outer.$getKind(this.$memoryAddress()), swiftArena);
147+ """ ,
148+ ]
149+ )
150+ }
151+
152+ @Test ( " Import: shadowed nested type name inside #if " )
153+ func shadowedNestedTypeName_ifConfig_java( ) throws {
154+ try assertOutput (
155+ input: """
156+ public struct Outer {
157+ #if SOME_FLAG
158+ public enum Kind {
159+ case alphaX
160+ }
161+ #else
162+ public enum Kind {
163+ case alpha
164+ case beta
165+ }
166+ #endif
167+
168+ public struct Inner {
169+ #if SOME_FLAG
170+ public enum Kind {
171+ case oneX
172+ }
173+ #else
174+ public enum Kind {
175+ case one
176+ case two
177+ }
178+ #endif
179+
180+ public var kind: Kind // Outer.Inner.Kind
181+ }
182+
183+ public var kind: Kind // Outer.Kind
184+ public var inner: Inner
185+ }
186+ """ ,
187+ . jni,
188+ . java,
189+ detectChunkByInitialLines: 1 ,
190+ expectedChunks: [
191+ """
192+ public Outer.Inner.Kind getKind(SwiftArena swiftArena) {
193+ return Outer.Inner.Kind.wrapMemoryAddressUnsafe(Outer.Inner.$getKind(this.$memoryAddress()), swiftArena);
194+ """ ,
195+ """
196+ public void setKind(Outer.Inner.Kind newValue) {
197+ Outer.Inner.$setKind(newValue.$memoryAddress(), this.$memoryAddress());
198+ """ ,
199+ ]
200+ )
201+ }
202+
203+ @Test ( " Import: shadowed nested type name in deeper nesting " )
204+ func shadowedNestedTypeName_deep_java( ) throws {
205+ try assertOutput (
206+ input: """
207+ public struct DiscordChannel {
208+ public struct Kind {
209+ public init() {}
210+ }
211+
212+ public struct Message {
213+ public struct MessageReference {
214+ public struct Kind {
215+ public init() {}
216+ }
217+ public var kind: Kind
218+ }
219+ }
220+ }
221+ """ ,
222+ . jni,
223+ . java,
224+ detectChunkByInitialLines: 1 ,
225+ expectedChunks: [
226+ // The `MessageReference.kind` property must reference the deeply nested
227+ // `DiscordChannel.Message.MessageReference.Kind`, not `DiscordChannel.Kind`.
228+ """
229+ public DiscordChannel.Message.MessageReference.Kind getKind(SwiftArena swiftArena) {
230+ """ ,
231+ """
232+ public void setKind(DiscordChannel.Message.MessageReference.Kind newValue) {
233+ """ ,
234+ ]
235+ )
236+ }
237+
238+ @Test ( " Import: shadowed nested type name declared via extension " )
239+ func shadowedNestedTypeName_extension_java( ) throws {
240+ try assertOutput (
241+ input: """
242+ public struct Outer {
243+ public enum Kind {
244+ case alpha
245+ case beta
246+ }
247+ }
248+
249+ extension Outer {
250+ public struct Inner {
251+ public enum Kind {
252+ case one
253+ case two
254+ }
255+
256+ public var kind: Kind // Outer.Inner.Kind
257+ }
258+ }
259+ """ ,
260+ . jni,
261+ . java,
262+ detectChunkByInitialLines: 1 ,
263+ expectedChunks: [
264+ // The `Inner.kind` property must reference `Outer.Inner.Kind`, not `Outer.Kind`.
265+ """
266+ public Outer.Inner.Kind getKind(SwiftArena swiftArena) {
267+ return Outer.Inner.Kind.wrapMemoryAddressUnsafe(Outer.Inner.$getKind(this.$memoryAddress()), swiftArena);
268+ """ ,
269+ """
270+ public void setKind(Outer.Inner.Kind newValue) {
271+ Outer.Inner.$setKind(newValue.$memoryAddress(), this.$memoryAddress());
272+ """ ,
273+ ]
274+ )
275+ }
276+
105277 @Test ( " Import: nested in enum " )
106278 func nestedEnums_java( ) throws {
107279 try assertOutput (
0 commit comments