Skip to content

Return early on intrinsics in couldContainTypeVariables #54377

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24004,6 +24004,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// we perform type inference (i.e. a type parameter of a generic function). We cache
// results for union and intersection types for performance reasons.
function couldContainTypeVariables(type: Type): boolean {
if (type.flags & TypeFlags.Intrinsic) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not understanding how the function would previously return true for the wildcard type (which is a TypeFlags.Any)? What am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The place I was referring to was inferTypes, which starts with a wildcard check, but if both sides are a wildcard we loop forever.

But, it checks for "could contain type var" before the wildcard logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but assuming both sides are wildcard types, how is it that we loop forever? That would require couldContainTypeVariables to return true for a TypeFlags.Any, and I'm not seeing how that happens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're totally right that couldContainTypeVariables should already be returning false for wildcardType, and yet, in my example it appeared to be returning true in the debugger!

But now, on main, my test doesn't fail... reverse bisecting says that it was "fixed" by changing lib.d.ts. So, I think there's some really odd corruption happening. Sounds like a fun debugging challenge.

This comment was marked as spam.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note the scary thing I'm seeing:

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traced this down to the new code in #53246, but it's absolutely bizarre. The flag is clearly there that says that "could contain type vars" is computed, and yet it still proceeds to overwrite it for no reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it out, see #54348 (comment)

const objectFlags = getObjectFlags(type);
if (objectFlags & ObjectFlags.CouldContainTypeVariablesComputed) {
return !!(objectFlags & ObjectFlags.CouldContainTypeVariables);
Expand Down