Hi. I trying to get parameter's default value of ...
# compiler
l
Hi. I trying to get parameter's default value of a function through a
ValueParameterDescriptor
, but when the function comes from a class file, it doesn't work.
Copy code
fun parseKtCallExpr(callExpr: KtCallExpression, bindingContext:BindingContext){
    val resolvedCall = callExpr.getResolvedCall(bindingContext)
    val defaultParam : ValueParameterDescriptor = resolvedCall.valueArguments[0].key // Suppose it has defaultvalue
    defaultParam.findPsi() as? KtParameter)?.defaultValue  // it works only when function come from code.
}
Is there any way to get it? Thanks.
y
maybe try
defaultParam.getCompileTimeInitializer()
u
The default value is an expression which can have arbitrarily complex code with side effects etc. It’s generated into the bytecode directly, and there’s no way to get it other than to load and parse that bytecode, which is likely very complicated for your use case
l
ok, thank you for the feedback