                     break
                 }
             }
-            
-            // Add pkgID to a stack used to keep track of multiple
-            // aliases specified in the package chain. Need to add
-            // pkgID here, otherwise need pkgID != pkgInChain check
-            // in the for loop above
-            pkgStack.append(pkgID)
-        }
-        
+        }
+        // Add pkgID to a stack used to keep track of multiple
+        // aliases specified in the package chain. Need to add
+        // pkgID here, otherwise need pkgID != pkgInChain check
+        // in the for loop above
+        pkgStack.append(pkgID)
+
         // Recursively (depth-first) walk the package dependency tree
         for pkgDep in builder.package.manifest.dependencies {
             walkPkgTreeAndGetModuleAliases(for: pkgDep.identity, with: packagesByIdentity, onError: observabilityScope, using: &pkgStack, output: &result)

}

// Create a map between a package and module aliases specified for the targets in the package.
private func gatherModuleAliases(for rootPkgID: PackageIdentity?,
                                 with packagesByIdentity: [PackageIdentity: ResolvedPackageBuilder],
                                 onError observabilityScope: ObservabilityScope) -> [PackageIdentity: [String: String]] {
    var result = [PackageIdentity: [String: String]]()
    
    // There could be multiple root packages but the common cases involve

    }

    // Gather all module aliases specified for targets in all dependent packages
    let packageAliases = gatherModuleAliases(from: packageBuilders, for: rootManifests.first?.key, with: packagesByIdentity, onError: observabilityScope)

    // Scan and validate the dependencies
    for packageBuilder in packageBuilders {
