Add nullability support for server parameter delegation#5486
Add nullability support for server parameter delegation#5486
Conversation
|
I'm a bit unsure how reliable |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe changes generalize the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
bjhham
left a comment
There was a problem hiding this comment.
Looks like an easy win 👍
I'm pretty sure isMarkedNullable works cross-platform on reified KTypes.
I don't know why we didn't just implement it that way in the first place...
|
FYI logged an issue to handle property delegation in the compiler plugin: |
| return getOrFail<R>(property.name) | ||
| public inline operator fun <reified R> Parameters.getValue(thisRef: Any?, property: KProperty<*>): R { | ||
| val typeInfo = typeInfo<R>() | ||
| return if (typeInfo.kotlinType?.isMarkedNullable == true && get(property.name) == null) { |
There was a problem hiding this comment.
Alternatively we can use null is R if we want to avoid creating TypeInfo instance
There was a problem hiding this comment.
This would probably allow us to keep getOrFailImpl signature untouched because of smart cast. But I'm not sure
There was a problem hiding this comment.
Yes, I forgot about null is R in reified generics. Seems like a much better solution here.
| * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.server.util.getValue) | ||
| * | ||
| * @throws MissingRequestParameterException if no values associated with name | ||
| * If [R] is nullable and no values are associated with the delegated property name, returns `null`. |
There was a problem hiding this comment.
Let's move this above [Report a problem] link
Subsystem
Server, core
Motivation
Currently it is not possible to use nullable values with parameter delegation.
Solution
This PR add support by removing the
: Anyconstraint and relying ontypeInfo.kotlinType?.isMarkedNullableto check if null is allowed or not.