Skip to content

[code-completion] Don't try to equate/convert GenericTypeParameterTypes when computing type relations of completion results #15411

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

Conversation

nathawes
Copy link
Contributor

For call argument completion, if the expected type and completion result type are
both GenericTypeParameterTypes, comparing them doesn't make sense as we can't account
for their different contexts at this point in the code, and hit assertions in the
constraint solver if we try.

For now, don't attempt to add a type relation for this case.

Resolves rdar://problem/38153332.

@nathawes
Copy link
Contributor Author

@swift-ci please test

if (!Ty->hasTypeParameter() && !ExpectedTy->hasTypeParameter()) {
if (Ty->isEqual(ExpectedTy))
return CodeCompletionResult::ExpectedTypeRelation::Identical;
if (isConvertibleTo(Ty, ExpectedTy, *DC))
Copy link
Contributor

Choose a reason for hiding this comment

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

If you look at isConvertibleTo it has some flags to turn type parameters or archetypes into type variables - this will produce a more accurate result. Might just be a matter of reusing the existing mechanism

Copy link
Contributor Author

@nathawes nathawes Mar 22, 2018

Choose a reason for hiding this comment

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

I tried changing isConvertibleTo to canPossiblyConvertTo (which passes openArchetypes=true) but does that make sense here since the two type parameters can have different generic contexts?

E.g. with the below snippet:

func foo<U, V>(_ _: U, _ _: V) where U: Sequence, V: Sequence {}
func bar<U, T>(lhs: T, rhs: U) where T: Collection {
  _ = foo(lhs, #^COMPLETE^#
}

when adding type relations to the completion items for lhs we end up comparing Ty = T to ExpectedTy = V and isEqual and canPossiblyConvertTo both return true. For rhs we compare Ty = U to ExpectedTy = V where isEqual is false and canPossiblyConvertTo is true.

airspeedswift and others added 7 commits April 27, 2018 17:40
This could take much longer, let's not lie
…es computing type relations of completion results

For call argument completion, if the expected type and completion result type are
both GenericTypeParameterTypes, comparing them doesn't make sense we can't account
for their different contexts at this point in the code, and hit assertions in the
constraint solver if we try.

For now, don't attempt to add a type relation for this case.
Resolves rdar://problem/38153332.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants