Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 should report duplicate identifier error #2394

Closed
1 task done
bvanjoi opened this issue Apr 10, 2024 · 4 comments · Fixed by #2615
Closed
1 task done

🐛 should report duplicate identifier error #2394

bvanjoi opened this issue Apr 10, 2024 · 4 comments · Fixed by #2615
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@bvanjoi
Copy link

bvanjoi commented Apr 10, 2024

Environment information

CLI:
  Version:                      1.6.4
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.11.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.2.4"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Workspace:
  Open Documents:               0

What happened?

  • code:
// npx @biomejs/biome check --apply code.ts
function f(a: number) {
  const a = 1; // expected throw error here but not.
}
  • playground:

https://biomejs.dev/playground/?code=ZgB1AG4AYwB0AGkAbwBuACAAZgAoAGEAOgAgAG4AdQBtAGIAZQByACkAIAB7AAoAIAAgAGMAbwBuAHMAdAAgAGEAIAA9ACAAMQA7AAoAfQA%3D

Expected result

Report errors like duplicated identifier

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@Conaclos Conaclos added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Apr 10, 2024
@Conaclos Conaclos self-assigned this Apr 10, 2024
@Conaclos
Copy link
Member

Conaclos commented Apr 10, 2024

The problem arises from the fact that noRedeclare checks for redeclarations in a given scope. Formal parameters and the function body are in different scopes.

@10Derozan
Copy link

Similarly, type parameters should not be in different scopes too.
For example:

function identity<T>(arg: T): T {
    const a: T = 1; // expect error
    return arg;
}

@Conaclos
Copy link
Member

function identity(arg: T): T {
const a: T = 1; // expect error
return arg;
}

I don't see any issue in your example...

@10Derozan
Copy link

function identity(arg: T): T {
const a: T = 1; // expect error
return arg;
}

I don't see any issue in your example...

Sorry, maybe they are not the similar error, in ts check it will fail.

The example should be

function identity<T>(arg: T): T {
    type T = number;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants