Skip to content
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

Enable aliasing a property that is forwarded in at the same level #24

Conversation

dfed
Copy link
Owner

@dfed dfed commented Jan 19, 2024

Fixes an issue where we could rename properties that were forwarded in above us, but not at the same level.

Due to our insight in #23 #23 (comment) (the PR on which this depends), I have rewritten Dependency.Source to have a separate case for an alias. By adding associated values to the enum, we were able to remove multiple optional properties and hard-to-keep-track-of tribal knowledge in the codebase.

Because we have updated the Dependency.Source which SafeDITool may persist, this PR is a breaking change and we will need to roll to a 0.3.0 when this merges.

On top of that, this is a pretty meaty change. I recommend reviewing this change in side-by-side view and turning off whitespace diffs to best understand what we were accomplishing before vs after.

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (12db159) 99.28% compared to head (277b8b4) 99.32%.

Additional details and impacted files

Impacted file tree graph

@@                          Coverage Diff                          @@
##           dfed--renamed-received-resolution      #24      +/-   ##
=====================================================================
+ Coverage                              99.28%   99.32%   +0.03%     
=====================================================================
  Files                                     37       38       +1     
  Lines                                   8304     8597     +293     
=====================================================================
+ Hits                                    8245     8539     +294     
+ Misses                                    59       58       -1     
Files Coverage Δ
...s/SafeDICore/Errors/FixableInstantiableError.swift 92.40% <100.00%> (ø)
...ore/Extensions/AttributeListSyntaxExtensions.swift 97.29% <100.00%> (+5.63%) ⬆️
Sources/SafeDICore/Generators/ScopeGenerator.swift 98.79% <100.00%> (-0.79%) ⬇️
Sources/SafeDICore/Models/Dependency.swift 100.00% <100.00%> (ø)
Sources/SafeDICore/Models/Initializer.swift 98.94% <100.00%> (-0.03%) ⬇️
Sources/SafeDICore/Models/Instantiable.swift 100.00% <ø> (ø)
Sources/SafeDICore/Models/Scope.swift 100.00% <100.00%> (ø)
...rces/SafeDICore/Visitors/InstantiableVisitor.swift 98.08% <100.00%> (-0.12%) ⬇️
Tests/SafeDICoreTests/FileVisitorTests.swift 100.00% <100.00%> (ø)
Tests/SafeDICoreTests/InitializerTests.swift 100.00% <100.00%> (ø)
... and 5 more

@@ -68,13 +68,10 @@ jobs:
linux:
name: Build and Test on Linux
runs-on: ubuntu-latest
container: swift:5.9
Copy link
Owner Author

Choose a reason for hiding this comment

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

following the advice here to avoid this kind of CI failure

@dfed dfed marked this pull request as ready for review January 19, 2024 08:43
@dfed dfed force-pushed the dfed--resolve-received-forwarded-properties branch 2 times, most recently from d7fa806 to 5c4ab59 Compare January 19, 2024 08:53
Comment on lines +266 to +276
let forwardedProperties = Set(
scope
.instantiable
.dependencies
.filter(\.isForwarded)
.map(\.property)
)
for receivedProperty in scope.receivedProperties {
let parentContainsProperty = receivableProperties.contains(receivedProperty)
if !parentContainsProperty {
let propertyIsForwarded = forwardedProperties.contains(receivedProperty)
if !parentContainsProperty && !propertyIsForwarded {
Copy link
Owner Author

Choose a reason for hiding this comment

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

this is the crux of the change that makes the new tests pass. We were already inspecting properties that were forwarded by a higher-up scope (they're in receivedProperties), but we weren't inspecting the properties in out scope.

case .ifConfigDecl:
return false
}
element.instantiableMacro != nil
Copy link
Owner Author

Choose a reason for hiding this comment

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

I simplified our macro access while I was adding associated types to the Dependency.Source enum in order to share this code.

@@ -35,7 +35,7 @@ public enum FixableInstantiableError: DiagnosticError {
public var description: String {
switch self {
case .dependencyHasTooManyAttributes:
"Dependency can have at most one of @\(Dependency.Source.instantiated), @\(Dependency.Source.received), or @\(Dependency.Source.forwarded) attached macro"
Copy link
Owner Author

Choose a reason for hiding this comment

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

Dependency.Source is no longer a String-backed enum, so we need to use constants for these raw values now.

@dfed
Copy link
Owner Author

dfed commented Jan 19, 2024

Closing in favor of #26

@dfed dfed closed this Jan 19, 2024
@dfed dfed deleted the dfed--resolve-received-forwarded-properties branch January 19, 2024 20:13
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.

1 participant