Skip to content

Type binds are incorrectly added to the functions ASTs as 'use' terms on import #729

@developedby

Description

@developedby

Reproducing the behavior

The error was initially reported by @NoamDev here #725 (comment)

Considering this program

# a.bend
from b import *

type MyType:
  A {data: u24}
  B {data: u24}
# b.bend
from a import *

Foo: MyType -> MyType
(Foo (MyType/A a)) = (MyType/A a)
(Foo (MyType/B b)) = (MyType/B b)
# main.bend
from a import *
main = "hello world"
> bend run main.bend
Errors:
In b :
In definition 'b/Foo':
  Unbound variable 'a/MyType'.
  Unbound variable 'a/MyType'.

Investigating this a little bit, it seems that the rebind use MyType = a/MyType in import files that import types.

This happens because all imported binds are considered the same for the import system instead of differentiating between functions and types. The logic for renaming type binds only checks local functions and not imported ones.

I think the way to fix this is to change imports::book::apply_import_binds, specifically to consider the correct sources in the loop that inserts binds in the variable adt_imports, but it seems that it'll require a considerable rework of the import bind logic.

System Settings

Bend commit: 9da1f49

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilationCompilation of terms and functions to HVM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions