[swift-evolution] Name disambiguation of computed property/function with same type defined in extensions

Paul Cantrell cantrell at pobox.com
Tue Jun 7 09:26:46 CDT 2016


> On Jun 7, 2016, at 7:09 AM, Charlie Monroe via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> We already have the concept of prefixing a type name with a module to disambiguate when two modules have the same type. I wonder if we could do the same thing to disambiguate between conflicting extensions?
>> 
>> 	import ModuleA
>> 	import ModuleB
>> 	
>> 	("hello world" as ModuleA.String).capitalized()	// Swift.String, with only APIs known to ModuleA
>> 	("hello world" as ModuleB.String).capitalized()	// Swift.String, with only APIs known to ModuleB
>> 	"hello world".capitalized()					// Still causes a compile-time error for ambiguity
> 
> This only introduces a new kind of ambiguity since you can have both ModuleA and ModuleB declare something like
> 
> class String {
> 	/// ...
> }
> 
> And now you have no idea if ModuleA.String refers to Swift.String extension in ModuleA or class String in ModuleA.

Perhaps the disambiguation should be on the extension method, not the type:

	import ModuleA
	import ModuleB
	
	"hello world”.ModuleA::capitalized()
	"hello world”.ModuleB::capitalized()

(Insert your own namespace separator if :: gives you unpleasant C++ flashbacks.)

P



More information about the swift-evolution mailing list