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

Unreported internal error when matching array of U8 #4554

Open
junetried opened this issue Nov 28, 2024 · 4 comments
Open

Unreported internal error when matching array of U8 #4554

junetried opened this issue Nov 28, 2024 · 4 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed needs investigation This needs to be looked into before its "ready for work"

Comments

@junetried
Copy link

The following code causes ponyc to return Error: internal failure not reported:

actor Main
    new create(env: Env) =>
        let arr: Array[U8 val] = [4; 5]
        match arr
        | [2; 3] => env.out.print("two and three")
        | [4; 5] => env.out.print("four and five")
        else
            env.out.print("something else")
        end

This modified version instead (correctly) gives a compile error, because Array does not implement eq:

actor Main
    new create(env: Env) =>
        let arr: Array[U8 val] = [4; 5]
        match arr
        | [U8(2); U8(3)] => env.out.print("two and three")
        | [U8(4); U8(5)] => env.out.print("four and five")
        else
            env.out.print("something else")
        end

Reproduced on my machine using ponyc 0.58.0-a161b7c9 and on the playground with ponyc 0.58.6-41be76e.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Nov 28, 2024
@SeanTAllen SeanTAllen added help wanted Extra attention is needed bug needs investigation This needs to be looked into before its "ready for work" good first issue Good for newcomers and removed discuss during sync Should be discussed during an upcoming sync labels Nov 28, 2024
@jemc
Copy link
Member

jemc commented Dec 3, 2024

The "internal failure not reported" message is shown when a compiler pass fails, but did not emit any errors explaining why it failed.

The right course of action here is for someone to troubleshoot (probably by running ponyc under a debugger like lldb or gdb) exactly where/why the pass is failing, and add code that emits an appropriate error for that.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Dec 3, 2024
@jemc jemc removed the discuss during sync Should be discussed during an upcoming sync label Dec 17, 2024
@SeanTAllen
Copy link
Member

in make_pattern_type in match.c, we return early with a NULL and no error when this check is hit:

  if(is_typecheck_error(pattern_type))
    return NULL;

is_typecheck_error being true means that we should have never gotten to that point and an error should have been given earlier. Or, it means some additional work is needed at that point (like a delayed reification being executed).

In our case at this point, the issue is that pattern_type is NULL.

The failure here happens in the expression pass.

In this particular case, we should be able to infer that the values are U8 because the array is U8. And we should be able to give a compiler error if the values are not representable as a U8. That however, is an extensive bit of code.

I think for our "good first issue" version of this, we could set an error message in make_pattern_type that we can't determine the type and that is a good resolution of the basic issue here and we could open a new issue for:

In this particular case, we should be able to infer that the values are U8 because the array is U8. And we should be able to give a compiler error if the values are not representable as a U8. That however, is an extensive bit of code.

Thoughts @ponylang/committer?

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Jan 20, 2025
@SeanTAllen
Copy link
Member

We discussed during sync and the "basic error that type of pattern couldn't be determined" is fine for anyone wanting to do the "good first issue" version of this.

@SeanTAllen
Copy link
Member

Note, the type antecedent stuff here works for non-array's just not arrays.

this compiles fine:

actor Main
    new create(env: Env) =>
        let arr = U8(4)
        match arr
        | 2 => env.out.print("two and three")
        | 3 => env.out.print("four and five")
        else
            env.out.print("something else")
        end

@SeanTAllen SeanTAllen removed discuss during sync Should be discussed during an upcoming sync bug labels Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed needs investigation This needs to be looked into before its "ready for work"
Projects
None yet
Development

No branches or pull requests

4 participants