diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index daf46df4..82a2dbd3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,6 @@ jobs: sudo xcodebuild -runFirstLaunch sudo xcrun simctl list sudo xcodebuild -downloadPlatform visionOS - sudo xcodebuild -runFirstLaunch - name: Build Framework run: xcrun xcodebuild -skipMacroValidation -skipPackagePluginValidation build -scheme SafeDI-Package -destination ${{ matrix.platforms }} @@ -116,8 +115,13 @@ jobs: run: sudo xcode-select --switch /Applications/Xcode_16.4.0.app/Contents/Developer - name: Install Pod run: bundle exec pod install --project-directory=Examples/ExampleCocoaPodsIntegration + - name: Download iOS + run: | + sudo xcodebuild -runFirstLaunch + sudo xcrun simctl list + sudo xcodebuild -downloadPlatform iOS -buildVersion 22F77 - name: Build CocoaPods Integration - run: xcrun xcodebuild build -scheme ExampleCocoaPodsIntegration -configuration Debug -workspace Examples/ExampleCocoaPodsIntegration/ExampleCocoaPodsIntegration.xcworkspace -destination 'platform=iOS Simulator,OS=18.4,name=iPad (10th generation)' # Explicitly test the Debug build. Our pod lint jobs are already testing the Release build. + run: xcrun xcodebuild build -scheme ExampleCocoaPodsIntegration -configuration Debug -workspace Examples/ExampleCocoaPodsIntegration/ExampleCocoaPodsIntegration.xcworkspace -destination 'platform=iOS Simulator,OS=18.5,name=iPad (10th generation)' # Explicitly test the Debug build. Our pod lint jobs are already testing the Release build. spm: name: Build and Test on Xcode 16 @@ -174,7 +178,6 @@ jobs: sudo xcodebuild -runFirstLaunch sudo xcrun simctl list sudo xcodebuild -downloadPlatform ${{ matrix.platforms }} - sudo xcodebuild -runFirstLaunch - name: Lint Podspec run: bundle exec pod lib lint --verbose --fail-fast --swift-version=6.0 --platforms=${{ matrix.platforms }} diff --git a/Sources/SafeDIMacros/Macros/InstantiableMacro.swift b/Sources/SafeDIMacros/Macros/InstantiableMacro.swift index 9c5b3f6f..b5cd0fcf 100644 --- a/Sources/SafeDIMacros/Macros/InstantiableMacro.swift +++ b/Sources/SafeDIMacros/Macros/InstantiableMacro.swift @@ -274,7 +274,9 @@ public struct InstantiableMacro: MemberMacro { return existingAssignment } else { var propertyAssignment = $0.asPropertyAssignment() - propertyAssignment.leadingTrivia = body.statements.first?.leadingTrivia ?? [] + if let leadingTrivia = body.statements.first?.leadingTrivia { + propertyAssignment.leadingTrivia = leadingTrivia + } return propertyAssignment } } diff --git a/Tests/SafeDIMacrosTests/InstantiableMacroTests.swift b/Tests/SafeDIMacrosTests/InstantiableMacroTests.swift index e96cc1a7..11512792 100644 --- a/Tests/SafeDIMacrosTests/InstantiableMacroTests.swift +++ b/Tests/SafeDIMacrosTests/InstantiableMacroTests.swift @@ -1935,6 +1935,76 @@ import SafeDICore } } + @Test + func declaration_fixit_updatesRequiredInitializerWhenAllDependenciesMissingFromInit() { + assertMacro { + """ + @Instantiable + public struct ExampleService: Instantiable { + public init() { + } + + @Received let received: Received + @Instantiated let instantiated: Instantiated + @Forwarded let forwarded: Forwarded + } + """ + } diagnostics: { + """ + @Instantiable + public struct ExampleService: Instantiable { + public init() { + ╰─ 🛑 @Instantiable-decorated type must have a `public` or `open` initializer with a parameter for each @Instantiated, @Received, or @Forwarded-decorated property. + ✏️ Add arguments for received: Received, instantiated: Instantiated, forwarded: Forwarded + } + + @Received let received: Received + @Instantiated let instantiated: Instantiated + @Forwarded let forwarded: Forwarded + } + """ + } fixes: { + """ + @Instantiable + public struct ExampleService: Instantiable { + public init( + received: Received, + instantiated: Instantiated, + forwarded: Forwarded + ) { + self.received = received + self.instantiated = instantiated + self.forwarded = forwarded + } + + @Received let received: Received + @Instantiated let instantiated: Instantiated + @Forwarded let forwarded: Forwarded + } + """ + } expansion: { + """ + public struct ExampleService: Instantiable { + public init( + received: Received, + instantiated: Instantiated, + forwarded: Forwarded + ) { + self.received = received + self.instantiated = instantiated + self.forwarded = forwarded + } + + let received: Received + let instantiated: Instantiated + let forwarded: Forwarded + + public typealias ForwardedProperties = Forwarded + } + """ + } + } + @Test func declaration_fixit_updatesRequiredInitializerWhenIncorrectAccessibilityOnInitAndOtherNonConformingInitializersExist() { assertMacro {