-
Notifications
You must be signed in to change notification settings - Fork 362
Make nullable parameters always optional #1528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make nullable parameters always optional #1528
Conversation
Treat nullable parameters that have no default value as if their default was set to null. Nullable parameters that have a default value explicitly set will continue to use that as their default.
parameter.type.isOptionalInputType() || | ||
|
||
// for nullable parameters that have no explicit default, we pass in null if not in input | ||
(parameter.type.isMarkedNullable && !parameter.isOptional) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably worth to wrap this expression in an extension function in kParameterExtensions
,
KParameter.isNotOptionalNullable()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -109,7 +109,11 @@ private fun <T : Any> mapToKotlinObject(input: Map<String, *>, targetClass: KCla | |||
// filter parameters that are actually in the input in order to rely on parameters default values | |||
// in target constructor | |||
val constructorParametersInInput = constructorParameters.filter { parameter -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will probably need to rename this
we can just call it constructorParameters
, and do
val constructorParameters = targetConstructor.parameters.filter { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thanks for the PR, i left couple of minor comments |
- add KParameter.isNotOptionalNullable() - minor cleanups in mapToKotlinObject
📝 Description
Treat nullable parameters that have no default value as if their default was set to null.
Nullable parameters that have a default value explicitly set will continue to use that as their default.
🔗 Related Issues
#1527