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

(Interpreter): Functions with return type object don't auto-box return values #359

Closed
sjbarag opened this issue Jan 21, 2020 · 0 comments · Fixed by #360
Closed

(Interpreter): Functions with return type object don't auto-box return values #359

sjbarag opened this issue Jan 21, 2020 · 0 comments · Fixed by #360
Labels
bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior e2e Affects this project's end-to-end test cases (the BrightScript sample files executed during testing) interpreter Affects this project's tree-walking interpreter

Comments

@sjbarag
Copy link
Owner

sjbarag commented Jan 21, 2020

RBI allows functions to declare a return type of object that return a value of any primitive type, and automatically boxes those primitive types to their object-like versions. Effectively all return types are thus allowed from as object functions, just like with as dynamic (or not declaring a return type). The only difference is that as dynamic (or not declaring a return type) doesn't automatically box return values.

function returnsObject_359() as object
    return "foo" ' => roString("foo")
    ' or:
    ' * return 3.14159 ' => roFloat(3.14159)
    ' * return invalid ' => roInvalid
end function

function returnsDynamic_359() as dynamic
    return "foo" ' => String("foo")
    ' or:
    ' * return 3.14159 ' => Float(3.14159)
    ' * return invalid ' => Invalid
end function

sub main()
    print returnsObject_359()
    print returnsDynamic_359()
end sub

Current behavior during execution:

/path/to/issue_359.brs(2,4-10): Attempting to return value of type String, but function returnsObject_359 declares return value of type Object
@sjbarag sjbarag added bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior e2e Affects this project's end-to-end test cases (the BrightScript sample files executed during testing) interpreter Affects this project's tree-walking interpreter labels Jan 21, 2020
sjbarag added a commit that referenced this issue Jan 21, 2020
…ypes

RBI will automatically box an intrinsic value when it's returned from a
function that declares an `as object` return type.  This makes the
function behave quite similarly to an `as dynamic` function, in that it
can seemingly return any value.  The only difference is that
`as dynamic` won't automatically box something like `return false` into
an `roBoolean`, while the `as object` variant will!

fixes #359
sjbarag added a commit that referenced this issue Jan 21, 2020
…ypes (#360)

RBI will automatically box an intrinsic value when it's returned from a
function that declares an `as object` return type.  This makes the
function behave quite similarly to an `as dynamic` function, in that it
can seemingly return any value.  The only difference is that
`as dynamic` won't automatically box something like `return false` into
an `roBoolean`, while the `as object` variant will!

fixes #359
sjbarag added a commit that referenced this issue Jan 27, 2020
Just like with #359 , function
parameters must *also* get automatically boxed.
sjbarag added a commit that referenced this issue Jan 27, 2020
Just like with #359 , function
parameters must *also* get automatically boxed.
lvcabral referenced this issue in lvcabral/brs-engine Mar 11, 2020
…ypes (#360)

RBI will automatically box an intrinsic value when it's returned from a
function that declares an `as object` return type.  This makes the
function behave quite similarly to an `as dynamic` function, in that it
can seemingly return any value.  The only difference is that
`as dynamic` won't automatically box something like `return false` into
an `roBoolean`, while the `as object` variant will!

fixes #359
lvcabral added a commit to lvcabral/brs-engine that referenced this issue Mar 11, 2020
Just like with sjbarag/brs#359 , function
parameters must *also* get automatically boxed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior e2e Affects this project's end-to-end test cases (the BrightScript sample files executed during testing) interpreter Affects this project's tree-walking interpreter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant