Skip to content

Commit

Permalink
fix: Fix panic from parse().unwrap() at generic inference (dudykr#1070
Browse files Browse the repository at this point in the history
)

**Description:**

```rs
 if r.is_num() {
      match src.parse() {
          Ok(v) => {
              return Type::Lit(LitType {
                  span,
                  lit: RTsLit::Number(RNumber { span, value: v, raw: None }),
                  metadata: Default::default(),
                  tracker: Default::default(),
              })
          }
          Err(..) => {
              return Type::Keyword(KeywordType {
                  span,
                  kind: TsKeywordTypeKind::TsNumberKeyword,
                  metadata: Default::default(),
                  tracker: Default::default(),
              })
          }
      }
  }
```
  • Loading branch information
sunrabbit123 committed Aug 20, 2023
1 parent 924ae3e commit 92ca8d2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,24 @@ impl Analyzer<'_, '_> {
tracker: Default::default(),
}),
};
match src.parse() {
Ok(v) => {
return Type::Lit(LitType {
span,
lit: RTsLit::Number(RNumber { span, value: v, raw: None }),
metadata: Default::default(),
tracker: Default::default(),
})
}
Err(..) => {
return Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsNumberKeyword,
metadata: Default::default(),
tracker: Default::default(),
})
}
}
}

if l.is_enum_type() || l.is_enum_variant() {
Expand Down

0 comments on commit 92ca8d2

Please sign in to comment.