Nike-Inc / Willow

Willow is a powerful, yet lightweight logging library written in Swift.
MIT License
1.35k stars 80 forks source link

Bugfix - Ambiguity in Escaping Closure APIs #32

Closed cnoon closed 7 years ago

cnoon commented 7 years ago

This PR fixes an issue we identified in the Willow 4.0.0 release where the escaping closure APIs are ambiguous when the closure is multiline. The compiler can't infer what the return type of the closure is unfortunately. You can declare the return type of the closure to fix the ambiguity error, but that's less than ideal.

See the migration guide for examples of the issue.

These changes fix the ambiguity by changing the log message string APIs to include the Message suffix. This fixes the ambiguity properly. The only question is whether this is the best way to name the APIs. I think this makes the usage the most readable.

log.debug(Message.requestStarted)
log.debugMessage("This is a test message")

I'm open to suggestions if anyone thinks there's a better way. If someone can come up with a backwards compatible solution that doesn't require declaring the return type to the compiler, I'm all ears.

AtomicCat commented 7 years ago

We should log a bug with Apple about this. It's really odd that the compiler can't disambiguate the return types.

AtomicCat commented 7 years ago

Crazy idea: make String conform to Message and drop the string only APIs (no idea if that actually works). Would that pollute the String namespace with name? Unclear if this is dumb or genius...