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

Unwrap optionals with dynamic cast #3580

Merged
merged 8 commits into from
Sep 13, 2024

Conversation

RZhang05
Copy link
Contributor

@RZhang05 RZhang05 commented Sep 11, 2024

Closes #3183

Description

Dynamic casting now unwraps optionals following the behaviour of Swift.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

Looks good! Nice to see the fix is kept simple 👌

runtime/interpreter/interpreter_expression.go Outdated Show resolved Hide resolved
Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Great work!

+1 on what @SupunS said, it's great that the implementation of this improvement is so simple.

Initially I was surprised this worked, I had assumed we would need to unbox only to the requested "level" of nesting. However, after looking at the rest of the implementation, this works because we box up the value again to the requested level again below (value = interpreter.ConvertAndBox(locationRange, value, valueSemaType, expectedType) 👍

@turbolent
Copy link
Member

Related: Swift's dynamic casting is actually way more complicated then I thought https://github.com/swiftlang/swift/blob/main/docs/DynamicCasting.md 😅

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Great work!

@turbolent turbolent merged commit 0ca61f0 into onflow:master Sep 13, 2024
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic casting should unwrap optional values
3 participants