Missing playground results for init
/deinit
in a class wrapped in a struct
#77498
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a decl that has
init
ordeinit
is nested inside another type, thoseinit
ordeinit
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 nestedtransformDecl()
calls. And that inner check was for too narrow of a type.The problem in this case was that the
dyn_cast<FuncDecl>(D)
was too narrow and didn’t include constructors/destructors. We wantdyn_cast<AbstractFunctionDecl>(D)
.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 theASTWalker
for the whole traversal?), but that’s a larger change, and so this is worth addressing with a safer short-term fix.Also, there are still missing results with accessors that are associated with properties in nested types. The fix for that will follow in a separate PR with its own unit test. Edit: The follow-on fix is here: #77530
Changes
dyn_cast<FuncDecl>
to adyn_cast<AbstractFunctionDecl>
in PlaygroundTransform.cppinit
anddeinit
(this test also tests the unnested case)rdar://137316110