Skip to content

fix error when exporting constants with type signatures in modules#14118

Merged
sholderbach merged 1 commit intonushell:mainfrom
sgvictorino:fix-module-export-const
Oct 22, 2024
Merged

fix error when exporting constants with type signatures in modules#14118
sholderbach merged 1 commit intonushell:mainfrom
sgvictorino:fix-module-export-const

Conversation

@sgvictorino
Copy link
Copy Markdown
Contributor

@sgvictorino sgvictorino commented Oct 17, 2024

Fixes #14023

Description

  • Prevents "failed to find added variable" when modules export constants
    with type signatures:
> module foo { export const bar: int = 2 }
Error: nu::parser::unknown_state

  × Internal error.
   ╭─[entry #1:1:21]
 1  module foo { export const bar: int = 2 }
   ·                     ─────────┬────────
   ·                              ╰── failed to find added variable
  • Returns name_is_builtin_var errors for names with type signatures:
> let env: string = "";
Error: nu::parser::name_is_builtin_var

  × `env` used as variable name.
   ╭─[entry #1:1:5]
 1  let env: string = "";
   ·     ─┬─
   ·      ╰── already a builtin variable

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reworking this. Looks good to me and great additional test on the special name detection.

Comment on lines +3132 to +3133
let name_span = Span::new(name_span.start, name_span.end - 1);
let var_name = bytes[0..(bytes.len() - 1)].to_vec();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that gets more explicit!

# Description

- Prevents "failed to find added variable" when modules export constants
  with type signatures:

```nushell
> module foo { export const bar: int = 2 }
Error: nu::parser::unknown_state

  × Internal error.
   ╭─[entry #1:1:21]
 1 │ module foo { export const bar: int = 2 }
   ·                     ─────────┬────────
   ·                              ╰── failed to find added variable
```

- Returns `name_is_builtin_var` errors for names with type signatures:

```nushell
> let env: string = "";
Error: nu::parser::name_is_builtin_var

  × `env` used as variable name.
   ╭─[entry #1:1:5]
 1 │ let env: string = "";
   ·     ─┬─
   ·      ╰── already a builtin variable
```
@sholderbach sholderbach merged commit 4968b6b into nushell:main Oct 22, 2024
@github-actions github-actions bot added this to the v0.100.0 milestone Oct 22, 2024
@fdncred fdncred added notes:fixes Include the release notes summary in the "Bug fixes" section A:modules Issues related to functionality of the module system. See also usage:modules labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:modules Issues related to functionality of the module system. See also usage:modules notes:fixes Include the release notes summary in the "Bug fixes" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

export const with a type signature causes Internal error: failed to find added variable

3 participants