Skip to content

Union Return type consistency - #1508

Merged
TwitchBronBron merged 4 commits into
v1from
return_type_consistency
Jul 16, 2025
Merged

Union Return type consistency#1508
TwitchBronBron merged 4 commits into
v1from
return_type_consistency

Conversation

@markwpearce

Copy link
Copy Markdown
Collaborator

Fixes #1488

If a union can be reduced to a primitive type, use that type for transpilation.

@markwpearce markwpearce added this to the v1.0.0 milestone Jun 9, 2025
@markwpearce
markwpearce changed the base branch from master to v1 June 9, 2025 12:30
Comment thread src/files/BrsFile.spec.ts Outdated
return "hello"
end function

function test2() as double

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think brightscript would coerce an integer into a longinteger, which would technically not be expected behavior. Should this one be dynamic?

@chrisdp what do you think of this one?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is double or float ... that goes to double.

integer or longinteger (test3) -> longinteger

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, yeah I was talking more generally about those use cases. Must have selected the wrong one. My concern applies to both integer or longinteger -> longinteger and double or float -> double.

If a function returns a float sometimes, or a double other times, I think the original underlying return type should be respected at runtime. By transpiling to the "more precise" data type, it'll prevent the less precise data type from ever leaving the function. There could be code on the outside looking for "is this a float" or "is this a double" that wouldn't be properly respected with this.

My vote would be for these two situations to transpile to dynamic.

@TwitchBronBron
TwitchBronBron enabled auto-merge (squash) July 16, 2025 11:33
@TwitchBronBron
TwitchBronBron merged commit ae89c77 into v1 Jul 16, 2025
8 checks passed
@TwitchBronBron
TwitchBronBron deleted the return_type_consistency branch July 16, 2025 11:38
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.

Return type consistency

2 participants