Result in Swift compatibility mode

Is Result supposed to be available in the compatibility modes of the Swift 5 compiler?

Seems to me it shouldn't be available -- but it is in beta 2 (and the Feb. 6 snapshot.)

Compatibility modes are expected to not break existing valid code; they're not required to not un-break existing invalid code, and they don't guarantee that code built on a new compiler will also build on an old compiler. The upshot is that it's fine for new declarations to appear in the standard library if they don't interfere with existing declarations. We changed lookup so that declarations in modules that depend on the standard library (i.e. all modules except the library itself) are reliably preferred over declarations in the standard library, so if you have an existing Result type in your code, it should take priority over the new Result type. This should allow code to incrementally adopt the new Result without necessarily switching the source-compatibility mode to Swift 5. Are you seeing a problem from the introduction of Result?

6 Likes

I’m not — this code’s result type wasn’t called result — so I didn’t see the shadowing behaviour. However I expected a compilation failure when I forced the compatibility mode; didn’t happen, and I couldn’t tell whether that was correct. Thanks for clarifying!