Skip to content

[SourceKit] Don’t transform type when printing if CurrentType can’t have members #36989

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
merged 1 commit into from
Apr 27, 2021

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Apr 21, 2021

Since 9ba892c we always transform CurrentType in ASTPrinter to be an interface type.

This causes issues when the variable type is a generic parameter type. Previously we had CurrentType set to a PrimaryArchetypeType. With the fix in d93ae06, we are mapping the archetype out of context to a GenericParamType. A GenericParamType, however, can’t have members, so we’re hitting an assertion when creating a TypeTransformContext. Since the entire type transformation in printTransformedTypeWithOptions is only affecting type members, we should be able to safely skip over the transformation if CurrentType can’t have any members.

Fixes rdar://76750555 [SR-14497]

…ave members

Since 9ba892c we always transform `CurrentType` in `ASTPrinter` to be an interface type.

This causes issues when the variable type is a generic parameter type. Previously we had `CurrentType` set to a `PrimaryArchetypeType`. With the fix in d93ae06, we are mapping the archetype out of context to a `GenericParamType`. A `GenericParamType`, however, can’t have members, so we’re hitting an assertion when creating a `TypeTransformContext`. Since the entire type transformation in `printTransformedTypeWithOptions` is only affecting type members, we should be able to safely skip over the transformation if `CurrentType` can’t have any members.

Fixes rdar://76750555 [SR-14497]
@ahoppen ahoppen requested a review from slavapestov April 21, 2021 09:54
@ahoppen
Copy link
Member Author

ahoppen commented Apr 21, 2021

@swift-ci Please test

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@@ -755,7 +755,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
void printType(Type T) { printTypeWithOptions(T, Options); }

void printTransformedTypeWithOptions(Type T, PrintOptions options) {
if (CurrentType && Current) {
if (CurrentType && Current && CurrentType->mayHaveMembers()) {
if (T->hasArchetype()) {
// Get the interface type, since TypeLocs still have
// contextual types in them.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if the mapTypeOutOfContext() is needed at all...

Copy link
Member Author

Choose a reason for hiding this comment

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

It appears to be not. I’ll set up a follow-up PR removing it.

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.

2 participants