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

Feed the 'this' type as a type argument to constraints during relation checking #7290

Merged
merged 7 commits into from
May 2, 2016

Conversation

DanielRosenwasser
Copy link
Member

Fixes #7276.

@ahejlsberg @sandersn @RyanCavanaugh can you take a look?

Right now, the types are being instantiated with their target. Is this sufficient?

@DanielRosenwasser DanielRosenwasser changed the title Instantiate type parameter constraints with themselves for their 'this' types. Feed the 'this' type as a type argument to constraints during relation checking Feb 29, 2016
if (!constraint || constraint.flags & TypeFlags.Any) {
constraint = emptyObjectType;
}

// The constraint may need to be further instantiated with its 'this' type.
constraint = getTypeWithThisArgument(constraint);
Copy link
Member

Choose a reason for hiding this comment

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

Let me check my understanding: an unconstrained type parameter gets 'any' or '{}' as its constraint, which shouldn't have a this-type, so this is a no-op there. Am I right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup. I could have introduced an else branch, but I figured that this would be a little simpler to read. I'm open to changing it.

Copy link
Member

Choose a reason for hiding this comment

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

No, I think it's fine. Just checking.

Copy link
Member

Choose a reason for hiding this comment

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

You want to instantiate the constraint with source as the this-type parameter, so this line should be:

constraint = getTypeWithThisArgument(constraint, source);

As you have it now you're instantiating the constraint with its own this-type as the this-type parameter. I think the reason it works with the example in the bug is because the this-type of Something is assignable to the this-type of Bar, but it's not the right solution.

@sandersn
Copy link
Member

👍

@mhegazy
Copy link
Contributor

mhegazy commented Apr 21, 2016

@DanielRosenwasser can you update the PR and respond to the remaining comments.

@DanielRosenwasser DanielRosenwasser merged commit 10d09a7 into master May 2, 2016
@DanielRosenwasser DanielRosenwasser deleted the thisTypesInBasePropAndContainer branch May 2, 2016 05:54
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants