Skip to content

Exported constants in modules with a dash in the name aren't accessible #14252

Closed

Description

@132ikl

Describe the bug

If a module has a dash in its name, and it exports a constant, it's not possible to access the constant when importing the entire module.

How to reproduce

> module foo-bar { export const VALUE = 123 }
> use foo-bar
> $foo_bar.VALUE
Error: nu::parser::variable_not_found

  × Variable not found.
   ╭─[entry #9:1:1]
 1 │ $foo_bar.VALUE
   · ────┬───
   ·     ╰── variable not found. Did you mean '$foo-bar'?
   ╰────
> $foo-bar.VALUE
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #10:1:1]
 1 │ $foo-bar.VALUE
   · ────┬───
   ·     ╰── expected valid variable name
   ╰────

Expected behavior

I expected to be able to access the constant with $foo_bar.VALUE.

Configuration

key value
version 0.99.2
major 0
minor 99
patch 2
branch makepkg
commit_hash 8b19399
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.80.1 (3f5fd8dd4 2024-08-06)
rust_channel 1.80.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.80.1 (376290515 2024-07-16)
build_time 2024-11-04 09:00:06 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash
installed_plugins custom_values 0.1.0, example 0.98.0, explore 0.99.1, formats 0.98.0, gstat 0.98.0, inc 0.98.0, jwalk 0.8.0, polars 0.98.0, query 0.98.0, stress_internals 0.98.0

Activity

  1. added
    status:needs-triage
    on Nov 4, 2024
  2. added
    category:bug
    A:scoping/name-resolution
    on Nov 5, 2024
  3. sgvictorino commented on Nov 15, 2024

    @sgvictorino
    Contributor

    Maybe the valid characters for module names should be constrained like identifiers, while allowing -?

  4. added a commit that references this issue on Dec 5, 2024
    234484b
  5. added this to the v0.101.0 milestone on Dec 5, 2024
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

    A:scoping/name-resolutioncategory:bugstatus:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions