[swift-users] Are all extensions from all modules exported on mass?
Jordan Rose
jordan_rose at apple.com
Thu Apr 20 12:09:25 CDT 2017
It's a longstanding bug, but a bug we can't fix easily, and one whose fix would probably break user code. It's tracked by SR-3908 <https://bugs.swift.org/browse/SR-3908>. (The description's a little different but it's the same underlying issue.)
Jordan
> On Apr 19, 2017, at 22:13, Howard Lovatt via swift-users <swift-users at swift.org> wrote:
>
> Hi,
>
> If I have the *same* extension in two *different* modules, ModuleA and ModuleB, and ModuleC uses both modules, but in *seperate* files, then there is still ambiguity about which extension to call:
>
> ModuleA
> A.swift
> public protocol P {
> func m() -> String
> }
> extension Int: P {
> public func m() -> String { return "AP.m" }
> }
> ModuleB
> B.swift
> public protocol P {
> func m() -> String
> }
> extension Int: P {
> public func m() -> String { return "BP.m" }
> }
> ModuleC
> A.swift
> import ModuleA
> func am(_ i: Int) -> String { return i.m() }
> B.swift
> import ModuleB
> func bm(_ i: Int) -> String { return i.m() }
> main.swift
> let i = 0
> print(am(i))
> print(bm(i))
>
> Gives the following errors when built:
>
> sunzero-ln:ModuleC lov080$ swift build
> Fetching /Users/lov080/Google Drive/Swift/Examples/Example Module Clashes/ModuleA
> Fetching /Users/lov080/Google Drive/Swift/Examples/Example Module Clashes/ModuleB
> Cloning /Users/lov080/Google Drive/Swift/Examples/Example Module Clashes/ModuleA
> Resolving /Users/lov080/Google Drive/Swift/Examples/Example Module Clashes/ModuleA at 1.0.0
> Cloning /Users/lov080/Google Drive/Swift/Examples/Example Module Clashes/ModuleB
> Resolving /Users/lov080/Google Drive/Swift/Examples/Example Module Clashes/ModuleB at 1.0.0
> Compile Swift Module 'ModuleB' (1 sources)
> Compile Swift Module 'ModuleA' (1 sources)
> Compile Swift Module 'ModuleC' (3 sources)
> /Users/lov080/Google Drive/Swift/Examples/Example Module Clashes/ModuleC/Sources/B.swift:3:38: error: ambiguous use of 'm()'
> func bm(_ i: Int) -> String { return i.m() }
> ^
> ModuleA.Int:2:17: note: found this candidate
> public func m() -> String
> ^
> ModuleB.Int:2:17: note: found this candidate
> public func m() -> String
> ^
> /Users/lov080/Google Drive/Swift/Examples/Example Module Clashes/ModuleC/Sources/A.swift:3:38: error: ambiguous use of 'm()'
> func am(_ i: Int) -> String { return i.m() }
> ^
> ModuleA.Int:2:17: note: found this candidate
> public func m() -> String
> ^
> ModuleB.Int:2:17: note: found this candidate
> public func m() -> String
> ^
> <unknown>:0: error: build had 1 command failures
> error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/lov080/Google\ Drive/Swift/Examples/Example\ Module\ Clashes/ModuleC/.build/debug.yaml
>
> Is this the expected behaviour or a bug?
>
> Thanks in advance for any help,
>
> -- Howard.
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170420/c9fc7303/attachment.html>
More information about the swift-users
mailing list