@@ -130,5 +130,34 @@ class GeneratorOptions {
130
130
}
131
131
132
132
self . implementationOnlyImports = implementationOnlyImports
133
+
134
+ // ------------------------------------------------------------------------
135
+ // Now do "cross option" validations.
136
+
137
+ if self . implementationOnlyImports && self . visibility != . internal {
138
+ throw GenerationError . message ( message: """
139
+ Cannot use @_implementationOnly imports when the proto visibility is public or package.
140
+ Either change the visibility to internal, or disable @_implementationOnly imports.
141
+ """ )
142
+ }
143
+
144
+ // The majority case is that if `self.protoToModuleMappings.hasMappings` is
145
+ // true, then `self.visibility` should be either `.public` or `.package`.
146
+ // However, it is possible for someone to put top most proto files (ones
147
+ // not imported into other proto files) in a different module, and use
148
+ // internal visibility there. i.e. -
149
+ //
150
+ // module One:
151
+ // - foo.pb.swift from foo.proto generated with "public" visibility.
152
+ // module Two:
153
+ // - bar.pb.swift from bar.proto (which does `import foo.proto`)
154
+ // generated with "internal" visiblity.
155
+ //
156
+ // Since this support is possible/valid, there's no good way a "bad" case
157
+ // (i.e. - if foo.pb.swift was generated with "internal" visiblity). So
158
+ // no options validation here, and instead developers would have to figure
159
+ // this out via the compiler errors around missing type (when bar.pb.swift
160
+ // gets unknown reference for thing that should be in module One via
161
+ // foo.pb.swift).
133
162
}
134
163
}
0 commit comments