Skip to content

Commit 6c459f2

Browse files
authored
Work around a diagnostic using CommandLine.arguments on older toolchains. (#2622)
`CommandLine.arguments` is declared read/write in older toolchains and this causes an error diagnostic when it's used in Swift 6 mode. This PR uses `CommandLine.argc` and `CommandLine.unsafeArgv` directly instead so the diagnostic does not occur.
1 parent 94e1cc9 commit 6c459f2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/SwiftCompilerPlugin/CompilerPlugin.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ extension CompilerPlugin {
9292
}
9393
}
9494

95-
let pluginPath = CommandLine.arguments.first ?? "<unknown>"
95+
let pluginPath: String
96+
if CommandLine.argc > 0, let cPluginPath = CommandLine.unsafeArgv[0] {
97+
pluginPath = String(cString: cPluginPath)
98+
} else {
99+
pluginPath = "<unknown>"
100+
}
96101
throw CompilerPluginError(
97102
message:
98103
"macro implementation type '\(moduleName).\(typeName)' could not be found in executable plugin '\(pluginPath)'"

0 commit comments

Comments
 (0)