Method/Initializer parameter types now resolve to the local type if it exists #1347
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.
Background
In the latest 2.2.5 release, our templates seemed to have hit a regression where an associated type within an unrelated protocol would show up as the
type
for aMethodParameter
of an unrelated type. This led me to discover a subtle inconsistency between how types of method parameters are resolved compared to variables.When resolving a variable type from the syntax tree, it will be sure to check for the type name within the
containedTypes
because this type should take priority over any global type:Sourcery/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Variable+SwiftSyntax.swift
Lines 77 to 86 in 070d0b1
This handling was missing for
MethodParameter
which means that thetypeName
(and latertype
) would always beFoo
instead ofBar.Foo
.Changes
This change addresses the immediate issue of Method Parameter types not being correct by passing the parent
Type
into theFunctionParameterSyntax
initialiser which is used when walking the syntax tree.This however isn't quite a complete fix. While looking at the code, I spotted a few other gotchas:
Return types also aren't resolved with local nested types in mindBut I think that it's a beneficial one for now until some further work can be done to align type resolution. Anyway.. Feedback is welcome 🙏