Skip to content

[SourceKit] Don't report type for InjectIntoOptionalExpr #67015

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

Merged

Conversation

skrtks
Copy link
Contributor

@skrtks skrtks commented Jun 29, 2023

Fixes incorrectly reporting an optional type for an expression when the contextual type is optional.

fixes #66882
rdar://111462279

Comment on lines 670 to 676
// We should not report a type for InjectIntoOptionalExpr
if (isa<InjectIntoOptionalExpr>(E))
return false;
Copy link
Member

@rintaro rintaro Jun 29, 2023

Choose a reason for hiding this comment

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

Cursor-info ignores all isImplicit() expressions including InjectIntoOptionalExpr. Could you try:

Suggested change
// We should not report a type for InjectIntoOptionalExpr
if (isa<InjectIntoOptionalExpr>(E))
return false;
if (E->isImplict())
return false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that works, but I think we should add an exception for OptionalEvaluationExpr, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, currently, in case of an implicit DotSyntaxCallExpr like in let a = 1 + 2, we expect the type of + to be (Int, Int) -> Int. With your suggested change that becomes (Int.Type) -> (Int, Int) -> Int. Is that correct, or do you think we should also opt in for reporting types of implicit DotSyntaxCallExpr?

Comment on lines 41 to 44
// CHECK: (395, 398): String?
// CHECK: (418, 423): String
// CHECK: (457, 458): String
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind adding the other type here? Not sure if it's the "Hey", "Bye" or c 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem :)

Fixes incorrectly reporting an optional type for an expression when the contextual type is optional.

fixes swiftlang#66882
rdar://111462279
@skrtks skrtks force-pushed the sk-fix-incorrect-optional-types branch from 1dec944 to c210a08 Compare July 25, 2023 08:16
@skrtks skrtks requested a review from hamishknight as a code owner July 25, 2023 08:16
@bnbarham
Copy link
Contributor

@swift-ci please test

@skrtks skrtks requested a review from rintaro August 1, 2023 14:52
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@hamishknight
Copy link
Contributor

@swift-ci please test

@hamishknight hamishknight merged commit c0e2d5e into swiftlang:main Aug 3, 2023
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.

SourceKit expression type request returns optional type for expression that is not optional
4 participants