Skip to content

Type checking fails when records are defined in a world with functions #88

@alec-deason

Description

@alec-deason

I think this is actually a bug but it may not be one that idiomatic wit files would trigger so it may not be an important issue but I'll post it anyway just in case.

When records are defined in a world along side functions which use the record type, the functions are generated first in the binding's init.py file so that type checking fails due to the undefined type.

For example, this wit file will not produce usable bindings:

package example:broken;

world broken-world {
    record a-record {
        field: s32
    }

    import get-a-record: func() -> a-record;
    export do-stuff: func() -> a-record;
}

My naive fix was to stick from __future__ import annotations at the top of the __init__.py file and that does work. But then I realized that the idiomatic thing to do seems to be to put type definitions in a separate types interface and import from there. Doing that produces valid bindings without having to change componentize_py at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions