Skip to content

[IDE] Resolve [.]Type completion for (any P). to produce singleton metatype instead of existential metatype #73163

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Rajveer100
Copy link
Contributor

Resolves #65843

The type completion for (any P). is a singleton meta type which currently falsely produces any P., i.e, an existential meta type.

@Rajveer100
Copy link
Contributor Author

@AnthonyLatsis
Could you trigger the CI to see if it breaks other tests?

@AnthonyLatsis
Copy link
Collaborator

@swift-ci please smoke test Linux

@Rajveer100
Copy link
Contributor Author

Rajveer100 commented Apr 20, 2024

Currently IDE/complete_value_expr.swift test fails. Would the following also be considered a singleton meta type:

protocol ExistentialProto {
  static func staticMethod()
  func instanceMethod()
}

func testExistential() {
  let _ = ExistentialProto.#^PROTOCOLTYPE_DOT_1^#
// PROTOCOLTYPE_DOT_1: Begin completions, 3 items
// PROTOCOLTYPE_DOT_1-DAG: Keyword[self]/CurrNominal:          self[#(any ExistentialProto).Type#]; name=self
// PROTOCOLTYPE_DOT_1-DAG: Keyword/CurrNominal:                Protocol[#(any ExistentialProto).Type#]; name=Protocol
// PROTOCOLTYPE_DOT_1-DAG: Keyword/CurrNominal:                Type[#any ExistentialProto.Type#]; name=Type

@AnthonyLatsis
Copy link
Collaborator

What are your thoughts on these three completions: Does either look incorrect to you? If so, why?

@Rajveer100
Copy link
Contributor Author

Rajveer100 commented Apr 20, 2024

I think according to my changes since we are checking the canonical type to be ExistentialMetatypeType, the completion should be Type[#(any ExistentialProto).Type#]

@AnthonyLatsis
Copy link
Collaborator

P.Type is equivalent to any P.Type.

I think accordingly my changes since we are checking the canonical type to be ExistentialMetatypeType

According to this logic, the result of appending .Type is:

  • An existential metatype if the type we are completing is also an existential metatype. This is not true: appending .Type to (any P.Type), which is an existential metatype, produces the singleton metatype (any P.Type).Type.
  • A singleton metatype otherwise. This is also not true: appending .Type to any P, which is not an existential metatype, produces the existential metatype any P.Type.

@Rajveer100
Copy link
Contributor Author

At the moment, the expected output as per my logic is Type[#(any ExistentialProto).Type#] which obviously fails. What I meant to say is, if the test is right, i.e, it's an existential meta type, the canonical type parameter which I added to the conditional check should succeed yielding the result.

@AnthonyLatsis
Copy link
Collaborator

#65843 (comment)

@Rajveer100
Copy link
Contributor Author

In terms of the implementation, I feel like the syntactic sugar for parenthesis, i.e (...) affects the outcome although the canonical type is correctly parsed for the AST?

@AnthonyLatsis
Copy link
Collaborator

What do you mean by outcome, and what type are you referring to?

@Rajveer100 Rajveer100 force-pushed the branch-for-issue-65843 branch from 0fd78cb to 69e67bb Compare April 22, 2024 12:41
@Rajveer100
Copy link
Contributor Author

With the latest changes, the test passes.

@AnthonyLatsis
Copy link
Collaborator

Please check that other IDE tests pass too.

@Rajveer100
Copy link
Contributor Author

All tests pass:

Testing Time: 40.10s
  Excluded         : 9854
  Unsupported      :    6
  Passed           :  480
  Expectedly Failed:    1

2 warning(s) in tests

@AnthonyLatsis
Copy link
Collaborator

@swift-ci please smoke test Linux

@Rajveer100
Copy link
Contributor Author

@AnthonyLatsis
Are there any other changes needed?

@Rajveer100 Rajveer100 force-pushed the branch-for-issue-65843 branch from 69e67bb to d27484a Compare April 24, 2024 14:31
@Rajveer100 Rajveer100 force-pushed the branch-for-issue-65843 branch 2 times, most recently from 1f0eb6d to 6bffda5 Compare March 15, 2025 12:45
@Rajveer100 Rajveer100 changed the title [IDE] Resolve [.]Type completion for (any P). to produce singleton metatype instead of existential metatype. [IDE] Resolve [.]Type completion for (any P). to produce singleton metatype instead of existential metatype Mar 15, 2025
@Rajveer100
Copy link
Contributor Author

@AnthonyLatsis

…tatype instead of existential metatype.

Resolves swiftlang#65843

The type completion for (any P). is a singleton meta type
which currently falsely produces any P., i.e, an existential meta type.
@Rajveer100 Rajveer100 force-pushed the branch-for-issue-65843 branch from 6bffda5 to f64014a Compare March 15, 2025 12:52
@Rajveer100
Copy link
Contributor Author

@ahoppen
Could you review this?

@AnthonyLatsis
Copy link
Collaborator

Have you tried running the test locally?

@Rajveer100
Copy link
Contributor Author

Yes, of course I did.

@Rajveer100
Copy link
Contributor Author

Could you trigger the CI bot?

@AnthonyLatsis
Copy link
Collaborator

@swift-ci please smoke test macOS

@Rajveer100
Copy link
Contributor Author

Build failure seems unrelated?

@Rajveer100
Copy link
Contributor Author

Could you trigger CI once again?

@AnthonyLatsis
Copy link
Collaborator

@swift-ci please smoke test macOS

@Rajveer100
Copy link
Contributor Author

CI looks good now.

@Rajveer100
Copy link
Contributor Author

@AnthonyLatsis
Ping :)

Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis left a comment

Choose a reason for hiding this comment

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

Please make sure these cases work too:

P.#^TOKEN1^#             // Type[#any P.Type#]
((P)).#^TOKEN2^#         // Type[#any P.Type#]
(P.Type).#^TOKEN3^#      // Type[#any P.Type.Type#]
(any P).Type.#^TOKEN4^#  // Type[#(any P).Type.Type#]
(any P.Type).#^TOKEN5^#  // Type[#(any P.Type).Type#]

@Rajveer100
Copy link
Contributor Author

Quick clarification:

((P)). can be deduced to (P). which is (any P)., so it shouldn't be existential right?

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.

[.]Type completion for (any P). shows it will produce an existential metatype
2 participants