Import single operator overload function

I'm trying to do an import for a specific function, but that function is an operator overload.

I know I can call import func ModuleName.functionName, but when the function is an operator overload, I can't figure out the right syntax to import it.

This is the function signature of the function I want to import.

public func ??<T>(lhs: T?, rhs: CustomType<T>) -> CustomType<T>

Is this just not possible currently?

I've tried the following:
import func ModuleName.??
import func ModuleName.(??)
import func ModuleName.??(_:_:)
import func ModuleName.??(lhs:rhs:)

Even when I do import enum CustomType, the function is not accessible. The only think that works is importing the entire module. Which I don't want to do, because I'm using this with an @_exported import statement and I don't want to make the entire module visible externally.

2 Likes

If I remember correctly, import ModuleName.TypeName doesn't work the way you'd think based on experience with other languages. Instead, it imports the whole ModuleName and limits the visibility of anything not TypeName to the compiler in that file. So it's not intended to do what you want here, which is why it hasn't grown the ability the reference any arbitrary symbol. I could be wrong though.

Have you tried moving the operator to a static extension of CustomType rather than a global?

Thanks for the extra context Jon. It sounds like @_exported import func isn't really helping as much as I'd hoped then. I'll probably just @_exported import the entire module, just don't like polluting the code completion on users of my library with additional unneeded symbols for my exported module.

Have you tried moving the operator to a static extension of CustomType rather than a global?

I did try that and it didn't work either. Thanks for the suggestion!