Skip to content

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

@tim-de

Description

@tim-de

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?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions