[swift-users] Are all extensions from all modules exported on mass?

Howard Lovatt howard.lovatt at gmail.com
Thu Apr 20 00:13:53 CDT 2017


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170420/0b6741a1/attachment.html>


More information about the swift-users mailing list