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

💅 Consistent crash on malformed ternary #1695

Closed
1 task done
fmajestic opened this issue Jan 28, 2024 · 9 comments · Fixed by #2619
Closed
1 task done

💅 Consistent crash on malformed ternary #1695

fmajestic opened this issue Jan 28, 2024 · 9 comments · Fixed by #2619
Assignees
Labels
A-Parser Area: parser L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@fmajestic
Copy link

fmajestic commented Jan 28, 2024

Environment information

CLI:
  Version:                      1.5.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v21.5.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "bun/1.0.25"

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

Workspace:
  Open Documents:               0

Rule name

lint/correctness/noUnusedVariables

Playground link

https://biomejs.dev/playground/?lintRules=all&code=dAB5AHAAZQAgAFQAbwBQAGEAcwBjAGEAbABDAGEAcwBlADwAUwAgAGUAeAB0AGUAbgBkAHMAIABzAHQAcgBpAG4AZwA%2BACAAPQAgAFMAIABlAHgAdABlAG4AZABzACAAYAAkAHsAaQBuAGYAZQByACAAUAByAGUAZgBpAHgAfQBgACAAPwAgADoAIAA7AA%3D%3D

Expected result

I'm getting this crash message:

Source Location: /home/runner/work/biome/biome/crates/biome_js_semantic/src/semantic_model/model.rs:334:46
Thread Name: main
Message: no entry found for key

Just as the placeholder for this field says, "It should not throw an error." 😝

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ematipico
Copy link
Member

ematipico commented Jan 29, 2024

The code that you pasted is not valid. Look at the playground, and even Prettier throws an error. And TS too

I'm not sure why we don't throw any diagnostic though, that's weird.

@fmajestic
Copy link
Author

Yeah, that's why I specifically said malformed ternary :D. const [xyy:?:""\n} = bar; is also invalid code but doesn't cause a hard crash.

I managed to narrow down the crash to that specific lint rule, but it happened while I was editing a file and typed in an "empty" ternary like that.

@ematipico
Copy link
Member

Yeah, but the issue is not the linter. It's a parser issue :)

@ematipico ematipico added S-Help-wanted Status: you're familiar with the code base and want to help the project A-Parser Area: parser S-Bug-confirmed Status: report has been confirmed as a valid bug L-JavaScript Language: JavaScript and super languages labels Jan 29, 2024
@togami2864
Copy link
Contributor

I'll take a look:)

@togami2864
Copy link
Contributor

The parser seems to be working fine, but the issue only reproduces in the production environment🤔

Screen.Recording.2024-02-04.at.16.43.37.mov

@ah-yu
Copy link
Contributor

ah-yu commented Feb 4, 2024

Hey @togami2864 , I took a look at this issue before and have some observations that I hope will be helpful:

  • This issue only happens when the NoUnusedVariable rule is enabled.
  • This issue disappears when the true branch of the condition type is not empty playground

I guess you can explore the issue more from here

// Delay the declaration of parameter types that are inferred.
// Their scope corresponds to the true branch of the conditional type.
self.infers
.push(TsTypeParameterName::unwrap_cast(node.syntax().clone()));

@togami2864
Copy link
Contributor

@ah-yu Awesome! Thank you!

@Conaclos
Copy link
Member

@togami2864 Are you still working on it? If not, I could take a look :)

@togami2864
Copy link
Contributor

How quickly did you fix it 🎉 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Parser Area: parser L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants