Inline functions for compile-time constant expressions

This compiles fine

@SomeAnnotation("a" + "b")

Shouldn’t this also compile?

@SomeAnnotation(inlinefunc("b"))
...
inline fun inlinefunc(b: String) : String = "a" + b

Inline function isn’t a constant expression, neither a macro.
These feature require more compilation time, so Kotlin does not support them.

Also many inline functions can’t be computed at compile time. They might depend on global variables, use reflection query the network, etc. As @fvasco said, they aren’t macros.

There’s a feature request about that – a modifier that being applied to a function allows it to participate in constant expressions:
https://youtrack.jetbrains.com/issue/KT-14652

2 Likes