diff --git a/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift b/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift index b6b6c20fffa..8e227186daf 100644 --- a/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift +++ b/Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift @@ -611,26 +611,21 @@ public final class SwiftModuleBuildDescription { // suppress warnings if the package is remote if self.package.isRemote { // suppress-warnings and the other warning control flags are mutually exclusive - var removeNextArg = false - args = args.filter { arg in - if removeNextArg { - removeNextArg = false - return false - } + var filteredArgs = [String]() + for arg in args { switch arg { case "-warnings-as-errors", "-no-warnings-as-errors": - return false + // Skip this flag + continue case "-Wwarning", "-Werror": - removeNextArg = true - return false + // Remove preceding -Xcc and skip this flag + filteredArgs.removeLast() default: - return true + filteredArgs.append(arg) } } - guard !removeNextArg else { - throw InternalError("Unexpected '-Wwarning' or '-Werror' at the end of args") - } - args += ["-suppress-warnings"] + args = filteredArgs + args.append("-suppress-warnings") } // Pass `-user-module-version` for versioned packages that aren't pre-releases.