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

case of fails to match a constant string against a string coming from JS #9202

Closed
radeusgd opened this issue Feb 27, 2024 · 1 comment · Fixed by #9203
Closed

case of fails to match a constant string against a string coming from JS #9202

radeusgd opened this issue Feb 27, 2024 · 1 comment · Fixed by #9203
Assignees
Labels

Comments

@radeusgd
Copy link
Member

Repro showing the issue:

from Standard.Base import all
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument

get_required_field key js_object = case js_object of
    _ : JS_Object -> js_object.get key if_missing=(Error.throw (Illegal_Argument.Error "Missing required field `"+key+"` in "+js_object.to_display_text+"."))
    _ -> Error.throw (Illegal_Argument.Error "Expected a JSON object, but got "+js_object.to_display_text+".")

foo json =
    x = get_required_field "type" json
    IO.println (x == "aws_auth")
    IO.println ("aws_auth" == x)
    v1 = case x of
        "aws_auth" -> "OK"
        other -> "not ok: "+other.to_display_text

    v2 = case ""+x+"" of
        "aws_auth" -> "OK"
        other -> "not ok: "+other.to_display_text

    [v1, v2]

main =
    j = """
        { "type": "aws_auth" }
    IO.println <| foo j.parse_json

Actual behaviour

True
True
[not ok: aws_auth, OK]

While == works we can see that case of fails to match the constant.

However, when we concatenate "", the JS string gets converted into Enso Text and then the match successfully works.

Expected behaviour

The script above should yield:

True
True
[OK, OK]
@radeusgd
Copy link
Member Author

I've already got a fix for this, so I'll put up a PR in a moment.

@radeusgd radeusgd mentioned this issue Feb 27, 2024
5 tasks
@radeusgd radeusgd moved this from ❓New to 👁️ Code review in Issues Board Feb 29, 2024
@jdunkerley jdunkerley moved this from 👁️ Code review to 🌟 Q/A review in Issues Board Feb 29, 2024
@jdunkerley jdunkerley moved this from 🌟 Q/A review to 👁️ Code review in Issues Board Feb 29, 2024
@mergify mergify bot closed this as completed in #9203 Feb 29, 2024
mergify bot pushed a commit that referenced this issue Feb 29, 2024
@github-project-automation github-project-automation bot moved this from 👁️ Code review to 🟢 Accepted in Issues Board Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant