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

expander expands builtin Intl types to any #649

Open
togami2864 opened this issue Feb 8, 2023 · 4 comments
Open

expander expands builtin Intl types to any #649

togami2864 opened this issue Feb 8, 2023 · 4 comments

Comments

@togami2864
Copy link
Contributor

Builtin Intl doesn't register as a built-in type properly.

Reproduction

Run

new Intl.Locale(); 

Then you can see the log like this though the type BCP47LanguageTag is string.

  DEBUG Analyzer.find_type('BCP47LanguageTag#0')
    at crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs:1831
    in Scope::find_type with name: BCP47LanguageTag#0
    in find_local_type
    in find_type with name: BCP47LanguageTag#0
    in Expander.expand_ref
    in Expander.expand_type
    in expand
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: (BCP47LanguageTag | Locale);
    in assign with lhs: "(BCP47LanguageTag | Locale);", rhs: "void;"
    in check_call_args
    in select_and_invoke
    in call_property
    in extract_call_new_expr_member
    in Stmt with line_col: "(1:1-1:19)"

  DEBUG Analyzer.find_type('BCP47LanguageTag#0')
    at crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs:1831
    in Scope::find_type with name: BCP47LanguageTag#0
    in Scope::find_type with name: BCP47LanguageTag#0
    in find_local_type
    in find_type with name: BCP47LanguageTag#0
    in Expander.expand_ref
    in Expander.expand_type
    in expand
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: (BCP47LanguageTag | Locale);
    in assign with lhs: "(BCP47LanguageTag | Locale);", rhs: "void;"
    in check_call_args
    in select_and_invoke
    in call_property
    in extract_call_new_expr_member
    in Stmt with line_col: "(1:1-1:19)"

  DEBUG Scope.find_type: failed to find type 'BCP47LanguageTag#0'
    at crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs:1205
    in find_local_type
    in find_type with name: BCP47LanguageTag#0
    in Expander.expand_ref
    in Expander.expand_type
    in expand
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: (BCP47LanguageTag | Locale);
    in assign with lhs: "(BCP47LanguageTag | Locale);", rhs: "void;"
    in check_call_args
    in select_and_invoke
    in call_property
    in extract_call_new_expr_member
    in Stmt with line_col: "(1:1-1:19)"

  ERROR (1) Failed to find type: BCP47LanguageTag#0
    at crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs:2174
    in Expander.expand_ref
    in Expander.expand_type
    in expand
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: (BCP47LanguageTag | Locale);
    in assign with lhs: "(BCP47LanguageTag | Locale);", rhs: "void;"
    in check_call_args
    in select_and_invoke
    in call_property
    in extract_call_new_expr_member
    in Stmt with line_col: "(1:1-1:19)"

  DEBUG [expander (time = 737.708µs)]: BCP47LanguageTag; => any;
    at crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs:2631
    in expand
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: (BCP47LanguageTag | Locale);
    in assign with lhs: "(BCP47LanguageTag | Locale);", rhs: "void;"
    in check_call_args
    in select_and_invoke
    in call_property
    in extract_call_new_expr_member
    in Stmt with line_col: "(1:1-1:19)"

  DEBUG [expander] expand: BCP47LanguageTag; => any;
    at crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs:738
    in expand
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: BCP47LanguageTag;
    in normalize with ty: (BCP47LanguageTag | Locale);
    in assign with lhs: "(BCP47LanguageTag | Locale);", rhs: "void;"
    in check_call_args
    in select_and_invoke
    in call_property
    in extract_call_new_expr_member
    in Stmt with line_col: "(1:1-1:19)"

type BCP47LanguageTag = string;

I guess it is due to the fact that builtin Intl is the only builtin type declared in namespace.

@kdy1 kdy1 added this to the v0.0.1: Correctness milestone Feb 8, 2023
@kdy1
Copy link
Member

kdy1 commented Feb 8, 2023

Did you try using dbg!? There's a footgun in dump_type_as_string....

Type::Module(m) => Type::any(m.span, Default::default()),

@kdy1
Copy link
Member

kdy1 commented Feb 8, 2023

I filed #650 because I think it's a footgun

@togami2864
Copy link
Contributor Author

Are you talking about logs? The actual type was also analyzed as any.

@kdy1
Copy link
Member

kdy1 commented Feb 8, 2023

I see, thank you for the investigation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants