SecretX
08/06/2022, 8:34 PMserialVersionUID
(example below) to Kotlin classes that implement (or inherit from) java.io.Serializable
. I know the compiler already creates those, but I wanted to simulate that (and maybe change the value to experiment with it).
I got the Gradle plugin and subplugin finished, alongside the CommandLineProcessor
and ComponentRegistrar
. The only part left is to figure out how to:
- Detect/find if the class already has a serialVersionUID
variable declared
- Add the serialVersionUID
exactly as it is below to the declaration of the class
And this last task is the one I can't figure out how to do. Should I use a ClassBuilderInterceptorExtension
, a ExpressionCodegenExtension
, or something else entire (because I saw there are bunchs of IR-somethings extensions to do a lot of things), what of those would be more appropriate for this purpose? And second, how to actually add fields to a class using these extensions?
private static final long serialVersionUID = 1L;
reactormonk
08/08/2022, 9:43 AMwhen
exhaustiveness without assigning the result to a variable? val x: Unit =
feels a bit silly.Jerry Yion
08/08/2022, 12:33 PM"Class ... is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
natario1
08/08/2022, 6:15 PM@Foo(val foo: Bool = true)
. I tried with annotation.symbol.owner.valueParameters[0].defaultValue!!.expression as IrConst<Bool>
, but the expression is actually an IrErrorExpression saying "Stub expression for default value of foo"
.natario1
08/08/2022, 6:42 PMmurdock
08/12/2022, 11:58 PMrrva
08/15/2022, 10:44 AMYoussef Shoaib [MOD]
08/19/2022, 10:42 AMJan Skrasek
08/20/2022, 8:14 AMinterface Destination {}
interface Dialog : Destination {}
inline fun <reified T : Destination> add() {
val isDialog1 = T is Dialog // does not compile
val isDialog2 = Dialog::class.java.isAssignableFrom(T::class.java) // works, but uses Java reflection
val isDialog3 = (typeOf<T>().classifier as KClass<T>).isSubclassOf(Dialog::class) // works, but uses Kotlin full reflection, doesn't it?
}
Isn't there any compiler optimized way to do this?
But THB, I'm not including kotlin full reflection to my dependencies, so maybe the third way IS optimized?natario1
08/21/2022, 8:45 AMe: java.lang.UnsupportedOperationException: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:my.sample.ProblematicCallbackImpl
at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor$TopLevelCodeContext.unsupported(IrToBitcode.kt:253)
I identified the offending code (irGet(thisClass.thisReceiver!!)
) but not a solution. I’m using the receiver to call a superclass function. I tried using superClass.thisReceiver!!
instead, but that creates a different error.jw
08/23/2022, 11:45 PMAskhar Aydarov
08/26/2022, 1:19 PMmajindong
08/27/2022, 11:03 AMholgerbrandl
08/29/2022, 2:35 PMimport kotlin.reflect.KClass
open class Provider {
open fun computeSmthg() = 42
}
class ConfigBuilder(val other: Int = 32) {
fun asProvider(): KClass<*> {
class CustomProvider : Provider() {
override fun computeSmthg(): Int {
return other
}
}
return CustomProvider::class
}
}
fun main() {
val providerClass = ConfigBuilder().asProvider()
require(providerClass.constructors.first().parameters.isEmpty())
val constructor = providerClass.constructors.first()
println(constructor.parameters)
println(constructor)
println(constructor.call())
}
which fails with
fun <init>(): com.systema.nexperia.epi.solver.`ConfigBuilder$asProvider$CustomProvider`
Exception in thread "main" java.lang.IllegalArgumentException: Callable expects 1 arguments, but 0 were provided.
Could I rewrite the code from above to actually create CustomProvider with a zero-arg constructor while referring to òther
property?Tóth István Zoltán
08/31/2022, 5:09 AMclass E {
fun b1() = Unit
val b = B(this::b1)
val c = B(this::b1)
}
class B(
val func: () -> Unit
)
Results in 4 classes:
• B.class
• E.class
• E$b$1.class
• E$c$1.class
In my specific use case I have a number of compiler plugin generated functions I pass, like in the example below. I could write a workaround by generating one function that gets the instance of E and an integer index and uses a when
to select the appropriate function. But that feels like a bit forced.
class E {
fun a1() = Unit
fun a2() = Unit
init {
B(this::a1)
B(this::a2)
}
}
David Bieregger
08/31/2022, 12:18 PMPHondogo
09/02/2022, 9:37 AMnatario1
09/02/2022, 3:49 PMIrFunction.isExpect
, but how to retrieve the actual (assuming they are compiled together)? Do I need a full module lookup, looking for a function with the same fq name?
• Given an IrFunction, how to implement IrFunction.isActual
?majindong
09/03/2022, 9:11 AMShreyash Saitwal
09/06/2022, 9:21 AMXavier F. Gouchet
09/06/2022, 9:43 AMreactormonk
09/07/2022, 8:25 AMsetContent {
...
suspend fun func1() {
func2()
}
suspend fun func2() {
func1()
}
}
Tells me func2
isn't defined in func1
Benni
09/07/2022, 8:38 PMorg.jetbrains.kotlin.psi.KtNamedFunction
. Anyone know how I can get the line number in which the function resides. I can get the location with startOffsetSkippingComments
and I assume I could calculate it myself by reading the file, but I was wondering, if there might be a different way.Peter
09/08/2022, 7:19 AMAugust Lilleaas
09/08/2022, 7:23 AMrespondHtml(status) { with(template) { apply() } }
. The use of with
here seems to be used to make sure that apply()
refers to the method that’s defined as a method on HTML<T>
that template
implements. If you write template.apply()
it resolves to the built in scope function apply
. What is it about the use of with
that makes Kotlin invoke the apply
method on HTML<T>
rather than the scope function?Gasan
09/09/2022, 4:12 PMnatario1
09/10/2022, 10:07 AMBar : Foo by FooImpl()
. Here Bar is a Foo without being a FooImpl, so it feels like it is a new direct implementation.August Lilleaas
09/10/2022, 11:07 AM@Test
, if it doesn’t compile, the test fails, but the other tests still runPHondogo
09/10/2022, 12:08 PMChachako
09/10/2022, 6:18 PMChachako
09/10/2022, 6:18 PMYoussef Shoaib [MOD]
09/10/2022, 6:33 PMComponentRegistrar
, so yes it is compatible. Just be careful though that your IR backend needs to be able to handle code both from the old FE frontend and also the FIR (K2) frontendChachako
09/11/2022, 6:24 AMYoussef Shoaib [MOD]
09/11/2022, 10:50 AM@Composable
functions outside of non-Composables) then you might find weird errors happening. Compose also most likely will receive a K2 update since again they don't rely on frontend that extensively AFAIK.Chachako
09/11/2022, 2:24 PMdmitriy.novozhilov
09/12/2022, 8:57 AMBindingContext
) which are deprecated but still accessible in combination of FE 1.0 + IR backend
So authors of those plugins should fix them before marking plugin as K2 compatibleChachako
09/12/2022, 2:34 PMdmitriy.novozhilov
09/12/2022, 3:08 PMChachako
09/12/2022, 4:10 PMIn such setup you could not use everything at onceUh... Do you mean that the following will fail? So I have to wait for other plugins to support the K2 API?
plugins {
id("org.jetbrains.compose") // Old compiler
id("io.realm.kotlin") // Old compiler
id("my.k2.compiler.plugin") // K2 compiler
}
dmitriy.novozhilov
09/13/2022, 7:46 AMmy.k2.compiler.plugin
will work
With K1 compiler only compose
and realm
allopen
) then it will work with both frontends