diff --git a/Sources/protoc-gen-swift/FileGenerator.swift b/Sources/protoc-gen-swift/FileGenerator.swift index 3aa749359..90fd06a69 100644 --- a/Sources/protoc-gen-swift/FileGenerator.swift +++ b/Sources/protoc-gen-swift/FileGenerator.swift @@ -91,6 +91,15 @@ class FileGenerator { p.print("import Foundation\n") + if self.generatorOptions.implementationOnlyImports, + self.generatorOptions.visibility == .public { + errorString = """ + Cannot use @_implementationOnly imports when the proto visibility is public. + Either change the visibility to internal, or disable @_implementationOnly imports. + """ + return + } + // Import all other imports as @_implementationOnly if the visiblity is // internal and the option is set, to avoid exposing internal types to users. let visibilityAnnotation: String = {