Skip to content
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

Handle Option correctly #266

Merged
merged 6 commits into from
Nov 23, 2023
Merged

Handle Option correctly #266

merged 6 commits into from
Nov 23, 2023

Conversation

honnix
Copy link
Member

@honnix honnix commented Nov 22, 2023

TL;DR

Handle Scala Option correctly by using correct type.

Type

  • Bug Fix
  • Feature
  • Plugin

Are all requirements met?

  • Code completed
  • Smoke tested
  • Unit tests added
  • Code documentation added
  • Any pending items have an associated Issue

Complete description

For case classes like:

case class ScalarNested(
    foo: String,
    bar: Option[String],
    nestedNested: Option[ScalarNestedNested]
)
case class ScalarNestedNested(foo: String, bar: Option[String])

the current code doesn't handle typing correctly because calling param.typeSignature.dealias.typeArgs.head.typeSymbol on Option type does not give what we need, and it should be param.typeSignature.dealias.typeArgs.head instead.

Also we are not handling nested Option correctly, although in practice there is no good reason to define Option[Option[String]].

Tracking Issue

NA

Follow-up issue

NA

Signed-off-by: Hongxin Liang <[email protected]>
Signed-off-by: Hongxin Liang <[email protected]>
Signed-off-by: Hongxin Liang <[email protected]>
Signed-off-by: Hongxin Liang <[email protected]>
Signed-off-by: Hongxin Liang <[email protected]>
Signed-off-by: Hongxin Liang <[email protected]>
value.asInstanceOf[Double].toFloat
} else if (tpe <:< typeOf[Option[Any]]) { // this has to be before Product check because Option is a Product
if (value == None) { // None is used to represent Struct.Value.Kind.NULL_VALUE when converting struct to map
None
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another bug fix. We have been converting things into Some(None), due to type conformation test failure against T in Option[T], which is exactly what this PR set off to fix. Bug on top of bug :(

Hopefully the extended unit tests and ITs cover better.

@andresgomezfrr andresgomezfrr merged commit 21c9e2e into master Nov 23, 2023
4 checks passed
@andresgomezfrr andresgomezfrr deleted the fix-nested-option branch November 23, 2023 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants