https://kotlinlang.org logo
#compiler
Title
# compiler
y

Youssef Shoaib [MOD]

08/17/2021, 4:57 AM
This could be useful as a first look into a (sort of) basic compiler plugin. Currently the code is lacking in comments, but that's because I cobbled it together in like 7 hours lol, and so if you notice any improvements or any mishaps that I've made, I'd love to hear your feedback!
s

shikasd

08/17/2021, 8:25 AM
I imagine that sometimes you still want to pass null in place of default :) Instead of relying on nulls, it could be something like
fun <T> default(): T
which throws error, then you can substitute calls to that function similarly to what you already did :)
y

Youssef Shoaib [MOD]

08/17/2021, 8:35 AM
It's meant to be for Java callers, that's the thing, and so any clever trickery with substituting functions and whatnot is not gonna work. It was honestly just a hasty implementation for a specific use-case, but isn't that kinda the whole point of compiler plugins lol? Like yeah simply it's just some legacy code that this person still wanted to support, and the thing is on the Kotlin side such trickery isn't needed since you can just refer to parameters by their name, but on Java the convention of null meaning substitute a sane default for me here is common enough to warrant the existence of this.
4 Views