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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughGeneric type constraints for Parameters delegated accessors were relaxed to allow nullable result types; implementation now returns null for absent parameters when the target type is nullable and preserves existing exceptions for non-nullable types and conversion failures. 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)
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: |
ktor-server/ktor-server-core/common/src/io/ktor/server/util/Parameters.kt
Outdated
Show resolved
Hide resolved
ktor-server/ktor-server-core/common/src/io/ktor/server/util/Parameters.kt
Outdated
Show resolved
Hide resolved
…getOrFailImpl`. This way both `getOrFail` and `getValue` now support nullable types.
|
@osipxd I updated the PR to move the nullability check in the actual implementation. This way we now also support nullable types for
Could you review again? Thank you for the careful review and pointing it out! 🙏 We're still getting a better outcome thanks to it! |
| } catch (cause: Exception) { | ||
| throw ParameterConversionException(name, typeInfo.type.simpleName ?: typeInfo.type.toString(), cause) | ||
| internal fun <R> Parameters.getOrFailImpl(name: String, typeInfo: TypeInfo): R { | ||
| return if (typeInfo.kotlinType?.isMarkedNullable == true && get(property.name) == null) { |
There was a problem hiding this comment.
Thank you for updating the PR!
Only one thing I've noticed. Compilation fails here: property is unresolved in this scope (probably should be name) 👀
There was a problem hiding this comment.
Yes, sorry about that! I was coding without loading the project 😅 Takes too much resources 💀
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.