You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Referencing multiple extension MemberNames with the same simple name leads to only one of them being imported, even though they have isExtension = true.
To Reproduce
Here is a unit test that exposes the problem:
/** * Referenced code: * * ```Kotlin * package pkg1 * * class Foo * * fun Foo.doSomething() {} * ``` * * ```Kotlin * package pkg2 * * class Bar * * fun Bar.doSomething() {} * ```*/
@Test
funtest() {
val fooClassName =ClassName("pkg1", "Foo")
val fooExtensionName =MemberName("pkg1", "doSomething", isExtension =true)
val barClassName =ClassName("pkg2", "Bar")
val barExtensionName =MemberName("pkg2", "doSomething", isExtension =true)
val fileSpec =FileSpec
.builder("app", "MyFile")
.addFunction(
FunSpec
.builder("doSomethingWith")
.addParameter("foo", fooClassName)
.addStatement("foo.%M()", fooExtensionName)
.build()
)
.addFunction(
FunSpec
.builder("doSomethingWith")
.addParameter("bar", barClassName)
.addStatement("bar.%M()", barExtensionName)
.build()
)
.build()
val expected =""" package app import kotlin.Unit import pkg1.Foo import pkg1.doSomething import pkg2.Bar import pkg2.doSomething public fun doSomethingWith(foo: Foo): Unit { foo.doSomething() } public fun doSomethingWith(bar: Bar): Unit { bar.doSomething() }""".trimIndent()
assertEquals(expected, fileSpec.toString())
}
Expected behavior
The result of generating the above code should be:
packageappimportkotlin.Unitimportpkg1.Fooimportpkg1.doSomethingimportpkg2.Barimportpkg2.doSomethingpublicfundoSomethingWith(foo:Foo): Unit {
foo.doSomething()
}
publicfundoSomethingWith(bar:Bar): Unit {
bar.doSomething()
}
Actual behavior
The generated code fully-qualifies one of the two extensions, which cannot be compiled:
packageappimportkotlin.Unitimportpkg1.Fooimportpkg1.doSomethingimportpkg2.BarpublicfundoSomethingWith(foo:Foo): Unit {
foo.doSomething()
}
publicfundoSomethingWith(bar:Bar): Unit {
bar.pkg2.doSomething()
}
Additional context
Using version 1.12.0
The text was updated successfully, but these errors were encountered:
Describe the bug
Referencing multiple extension
MemberName
s with the same simple name leads to only one of them being imported, even though they haveisExtension = true
.To Reproduce
Here is a unit test that exposes the problem:
Expected behavior
The result of generating the above code should be:
Actual behavior
The generated code fully-qualifies one of the two extensions, which cannot be compiled:
Additional context
Using version
1.12.0
The text was updated successfully, but these errors were encountered: