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

Default values in Record don't work as expected #7031

Open
rudolfvesely opened this issue Aug 27, 2024 · 4 comments
Open

Default values in Record don't work as expected #7031

rudolfvesely opened this issue Aug 27, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@rudolfvesely
Copy link

Hi everybody,

I'm using the most current ROC (build from Nix flake).

This should work:

something = \foo, { firstBar ? Both, secondBar } ->
    when firstBar is
        Start -> Str.concat secondBar foo
        End -> Str.concat foo secondBar
        Both ->
            foo
            |> something { firstBar: Start, secondBar }
            |> something { firstBar: End, secondBar }
expect
    x = something "aaa" { secondBar: "bbb" }
    x == "bbbaaabbb"

But it doesn't:

# This 2nd argument to something has an unexpected type:
#
# 30│      x = something "aaa" { secondBar: "bbb" }
#                              ^^^^^^^^^^^^^^^^^^^^
#
# The argument is a record of type:
#
#     { … }
#
# But something needs its 2nd argument to be:
#
#     { firstBar : [
#         Both,
#         End,
#         Start,
#     ], … }
#
# Tip: Looks like the firstBar field is missing.

Thank you.

@Anton-4 Anton-4 added the bug Something isn't working label Aug 27, 2024
@Anton-4
Copy link
Collaborator

Anton-4 commented Aug 27, 2024

Thanks for reporting this @rudolfvesely, I think this should indeed work.

As a workaround you can add this type annotation to fix it:

something : Str, { firstBar ? [Both, End, Start], secondBar : Str } -> Str

Note for future investigator, this version does work:

something = \foo, { firstBar ? Both, secondBar } ->
    when firstBar is
        Start -> Str.concat secondBar foo
        End -> Str.concat foo secondBar
        Both ->
            Str.concat foo secondBar
            
expect
    x = something "aaa" { secondBar: "bbb" }
    x == "aaabbb"

@rudolfvesely

This comment was marked as outdated.

@Anton-4

This comment was marked as outdated.

@Anton-4
Copy link
Collaborator

Anton-4 commented Aug 28, 2024

Likely cause

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

2 participants