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

brs doesn't automatically unbox parameters and return values #18

Closed
lvcabral opened this issue Sep 14, 2023 · 1 comment
Closed

brs doesn't automatically unbox parameters and return values #18

lvcabral opened this issue Sep 14, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@lvcabral
Copy link
Collaborator

lvcabral commented Sep 14, 2023

RBI automatically boxes function parameters and return values. As it turns out, RBI also unboxes function parameters and return values to match a function's declared signature. Consider this example:

sub main()
    boxed = createObject("roString")
    boxed.setString("lorem ipsum")
    print "type(boxed) = " type(boxed) " | boxed = " boxed

    unboxed = unboxing(boxed)
    print "type(unboxed) = " type(unboxed) " | unboxed = " unboxed
end sub

sub unboxing(s as string) as string
    print "type(s) = " type(s) " | s = " s
    return s
end sub

Inside of the unboxing function, s is always a primitive string and never an instance of roString. Similarly, the return value of unboxing is also always a primitive string and never an instance of roString.

brs currently doesn't handle this demotion properly, and throws type mismatch errors at runtime 😢

@lvcabral
Copy link
Collaborator Author

Another scenario with this same unboxing issue can be reproduced this way:

a = CreateObject("roInt",1)
? a+1

causes an error:

REPL(1,2-5): Attempting to add non-homogeneous values.
    left: Object
    right: Integer**

In case of a comparison is even worse, as it does not return an error so it silently return false if you compare a roInt with value 1 and the constant 1 like this:

a = CreateObject("roInt",1)
? a
1
? a=1
false

@lvcabral lvcabral added the bug Something isn't working label Sep 14, 2023
@lvcabral lvcabral closed this as completed Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant