Disambiguate between function and protocol

I'm having trouble convincing the compiler that I'm trying to refer to a function and not a protocol of the same name.

From Cucumberish I have this function:

void Then(NSString * definitionString, CCIStepBody body)

...where CIStepBody is a closure. Obviously it would be better if the function name weren't capitalized.

And from elsewhere in the project I also have a protocol named Then. (Again, not the best naming, but not something I can easily change)

The problem, now, is when I try to call the function Then() the compiler insists that I'm referring to the protocol instead:

'Then' cannot be constructed because it has no accessible initializers

If I try calling it as Cucumberish.Then(), the compiler thinks I'm talking about the Cucumberish class in the Cucumberish framework. So even though I have import Cucumberish at the top of my file, I can't use that as a module names to qualify other identifiers.

What other ways are there for me to convince the compiler that I'm talking about the function?

Wild guess:

Then(<params>) as Void

That didn't do it, unfortunately.

It turned out I was able to get the Then protocol renamed, so that avoids the problem this time. I'd still love to know how to solve that disambiguation in case it comes up again.

1 Like

Maybe it's worth filing a bug:

protocol X {}
func X(a: Int) {}

-> Invalid redeclaration of X(a:).
When you follow the naming standards, this will never happen — but still, this error makes no sense to me.

Terms of Service

Privacy Policy

Cookie Policy