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

Computing variance causes circularity error #53470

Closed
gabritto opened this issue Mar 23, 2023 · 0 comments · Fixed by #53549
Closed

Computing variance causes circularity error #53470

gabritto opened this issue Mar 23, 2023 · 0 comments · Fixed by #53549
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@gabritto
Copy link
Member

Bug Report

Sometimes we start to compute variances while we're in the middle of computing the types for e.g. a property, and then during variance computation, we try to compute the type for the same property again, so we error on that circularity. However, those circularity errors could be avoided if we were to "restart" when we start computing variances, i.e. for purposes of circularity detection, ignore the types we were previously computing. This becomes a larger problem when the error is or not present depending on the order in which things are declared, as in the example below.

This is a fork of issue #52813, which was fixed for the specific case where the thing that triggers a variance computation is a type assertion, and the fix implemented (#53261) was to defer the type comparability done for type assertions, to delay triggering variance computations that aren't immediately needed.
However, in scenarios where variance computation is triggered in other ways, the circularity error is still present and could be avoided:

🔎 Search Terms

variance circularity

⏯ Playground Link

Playground link with relevant code

💻 Code

class Bar<T> {
    num!: number;    // Swap to remove error
    Value = callme(this).num;
    Field: number = callme(this).num;
}
declare function callme(x: Bar<any>): Bar<any>;
declare function callme(x: object): string;

🙁 Actual behavior

Error: 'Value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)

🙂 Expected behavior

No error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants