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

Incompatible types in typeclass instances are not caught by the checker #600

Open
tim-de opened this issue Jun 16, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@tim-de
Copy link
Contributor

tim-de commented Jun 16, 2024

While looking into why the standard library wasn't building correctly for me, I found that that readByte for StandardInput
was trying to call an incompatible mono in the generated c code.

In the source I found that the implementations of the readByte and writeByte functions in the instances for StandardInput and StandardError respectively did not have the correct types in the function definition.

The typeclass definition demands that the instance type parameter matches the stream type

-- standard/src/IO/IO.aui
typeclass ByteInputStream(T: Type) is
    generic [R: Region]
    method readByte(stream: &![T, R]): Option[Nat8];
end;

But the implementation does not follow this

-- standard/src/IO/Terminal.aum
instance ByteInputStream(StandardInput) is
    generic [R: Region]
    method readByte(stream: &![StandardOutput, R]): Option[Nat8] is
        let stdin: Address[Nat8] := getStdin();
        let res: Int32 := fgetc(stdin);
        if res = EOF then
            return None();
        else
            return toNat8(res);
        end if;
    end;
end;

I have created a PR to fix the discrepancy in this code, but surely this should be getting caught by the type checker?

@eudoxia0 eudoxia0 self-assigned this Jun 19, 2024
@eudoxia0 eudoxia0 added the bug Something isn't working label Jun 19, 2024
@eudoxia0
Copy link
Member

Yes this is absolutely a bug in the type checker. Thanks for reporting and fixing the code!

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