Skip to content

Missing playground results for property accessors in a class wrapped in a struct #77530

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

abertelrud
Copy link
Contributor

@abertelrud abertelrud commented Nov 11, 2024

When a decl that has properties with accessors (get, set, willSet, didSet, etc) is nested inside another type, those accessor implementations aren't playground-transformed.

Details

The reason is that the playground transform uses an ASTWalker to get to the top-level structure, but then once it’s inside a type, it does directly nested transformDecl() calls. And that inner check is missing a case for accessors.

This is a follow-on fix to #77498.

Future work

It's unfortunate that the playground transform reaches decls in two different ways (using an ASTWalker to get to the top-level decls but then using directly nested calls below). This seems to be worth resolving at some point (perhaps by using the ASTWalker for the whole traversal?), but that’s a larger change, and so this is worth addressing with a safer short-term fix.

Changes

  • add an else-clause that checks if the declaration is a VarDecl, and if so, calls transformDecl() on each accessor in PlaygroundTransform.cpp
  • add a unit test for nested accessors (this test also tests the unnested case)

rdar://139656464

@abertelrud
Copy link
Contributor Author

@swift-ci Please smoke test

@abertelrud abertelrud changed the title [Playground] Missing playground results for property accessors in a class wrapped in a struct Missing playground results for property accessors in a class wrapped in a struct Nov 11, 2024
…lass wrapped in a struct

When a decl that has properties with accessors (`get`, `set`, `willSet`, `didSet`, `subscript(index:)`, etc) is nested inside another type, those accessor implementations aren't playground-transformed.

The reason is that the playground transform uses an `ASTWalker` to get to the top-level structure, but then once it’s inside a type, it does directly nested `transformDecl()` calls. And that inner check is missing a case for accessors.

This change adds an else-clause that checks if the declaration is a `VarDecl`, and if so, calls `transformDecl()` on each accessor.

It's unfortunate that the playground transform reaches decls in two different ways (using an `ASTWalker` to get to the top-level decls but then using directly nested calls below). That issue seems to be worth resolving at some point (perhaps by using the `ASTWalker` for the whole traversal?)... but that would be a larger change requiring more though, and so the missing results being fixed here are worth addressing with a safer short-term fix.

rdar://139656464
@abertelrud abertelrud force-pushed the eng/anders/139656464-nested-accessor-playground-results branch from 53cc8fc to 31f75c6 Compare December 5, 2024 22:17
@abertelrud
Copy link
Contributor Author

@swift-ci Please smoke test

@abertelrud
Copy link
Contributor Author

@xedin I've updated the PR — could I ask for another look? Thank you!

@abertelrud
Copy link
Contributor Author

@swift-ci Please smoke test linux

@abertelrud abertelrud merged commit d2cdf0f into main Dec 6, 2024
3 checks passed
@abertelrud abertelrud deleted the eng/anders/139656464-nested-accessor-playground-results branch December 6, 2024 17:41
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.

4 participants