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 value fields don't type check for closed records #6750

Open
quelgar opened this issue May 15, 2024 · 0 comments
Open

Default value fields don't type check for closed records #6750

quelgar opened this issue May 15, 2024 · 0 comments

Comments

@quelgar
Copy link
Sponsor

quelgar commented May 15, 2024

roc nightly pre-release, built from commit e5ea6dc4617 on Mon May 13 10:47:45 UTC 2024

In certain circumstances, default value records do not work as expected:

i = Num.toI32 1

# f1 is all fine
f1 = \{ a, b ? "DEFAULT" } -> (a < i, b)

expect f1 { a: 1 } == (Bool.false, "DEFAULT")

expect f1 { a: 1, b: "foo" } == (Bool.false, "foo")

# for f2, the first expect does not compile if the second expect exists
# unless the record parameter is open
f2 : { a : I32, b ? Str } -> (Bool, Str)
f2 = \{ a, b ? "DEFAULT" } -> (a < i, b)

expect f2 { a: 1 } == (Bool.false, "DEFAULT")

expect f2 { a: 1, b: "foo" } == (Bool.false, "foo")

results in:

── TYPE MISMATCH in Test.roc ───────────────────────────────────────────────────

This 1st argument to f2 has an unexpected type:

21│  expect f2 { a: 1 } == (Bool.false, "DEFAULT")
               ^^^^^^^^

The argument is a record of type:

    { … }

But f2 needs its 1st argument to be:

    { b : Str, … }

Tip: Looks like the b field is missing.

────────────────────────────────────────────────────────────────────────────────

If the type annotation is changed to an open record, it compiles:

f2 : { a : I32, b ? Str }* -> (Bool, Str)

Zulip topic.

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

No branches or pull requests

1 participant