Skip to content

A local named after a libm builtin (floor) breaks unrelated modules, with errors attributed to the wrong file #2064

Description

@nicolas-maman

Seen with aetherc from Aether 0.651.0 (Windows, ae3d).

A program with a local variable named floor:

on_start(state: ptr, e: *Engine) {
    floor = loader.plane(2, 10.0)
    core.model_set_position(floor, 0.0, 0.0, 0.0)
}

fails type checking with three errors that point at a different file altogether:

error[E0200]: cannot cast ptr to int with `as`: a value cast converts between a distinct type and its base, or between numeric types
  --> examples/gltf_viewer.ae:127:18
  --> examples/gltf_viewer.ae:128:18
  --> examples/gltf_viewer.ae:129:18

examples/gltf_viewer.ae has nothing at those lines; the errors are in an imported module (ae3d.noise, which does floor(x) as int), where the builtin floor now resolves to the program's *Model variable. Editing the program does not move the line numbers, which is what makes it hard to find: I bisected the whole file before guessing the name.

Two asks:

  1. A local should not shadow a builtin across module boundaries -- the module's floor(x) should stay libm's whatever a program names its variables -- or the compiler should refuse the shadowing with a message naming it.
  2. An error inside an imported module should name the module's file and line, not the main program with the module's line numbers.

Renaming the variable (ground) fixes it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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