Repository navigation
Description
| Previous ID | SR-898 |
| Radar | rdar://problem/19481048 |
| Original Reporter | mkadijk (JIRA User) |
| Type | Bug |
Environment
Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81) / Xcode Version 7.2.1 (7C1002) / iOS 9.2
Additional Detail from JIRA
| Votes | 18 |
| Component/s | Compiler |
| Labels | Bug |
| Assignee | None |
| Priority | Medium |
md5: ea3a4fb46f14a67b99d4cb07142d5803
blocks:
- SR-14195 Swift emits an invalid module interface when a public type has the same name as a module
Issue Description:
Given two modules with the same type, where one module has a type that has the same name as the module itself with generic parameters it will become impossible to explicitly refer to the type you want.
Example
Module A:
struct NoError: ErrorType {}Module B:
struct B<T> {}
struct NoError: ErrorType {}The app:
import A
import B
let ambiguousError: NoError // This correctly errors because it's ambiguous
let errorA: A.NoError // This correctly works since we make the module explicit
let errorB: B.NoError // This _incorrectly_ errors, complaining about required argumentsExpected behaviour
Only ambiguousError should give an error, the other two error constants should work since the module is specified to prevent ambiguous type errors.
What happend instead
The error we get with B.NoError is Reference to generic type 'B' requires arguments in <...>. The compiler incorrectly assumes we are referring to struct B instead of the module B. This makes it impossible to fix the ambiguity.
Workaround
It is possible to work around this by creating a typealias in a seperate file where we only import module B and there typealias BNoError = NoError then we can use the BNoError as the type of let errorB to work around the issue.
Activity
belkadan commentedon Mar 8, 2016
Needs design.
import … as …is one possible answer.swift-ci commentedon Mar 14, 2016
Comment by Evan Maloney (JIRA)
I've hit this issue as well, and have discovered that it doesn't require the use of generics to trigger it.
In my case, I have a package
LegacyStoreand a packageAppleTart, both of which contain a type namedUser.In the case of
LegacyStore,Useris an Objective-C class, and in the case ofAppleTart,Useris a Swift struct.Normally, I'd be able to refer to one as
LegacyStore.Userand the other asAppleTart.User, but when using this notation for an extension:...I get a compiler error on the extension declaration line:
Note that the
LegacyStore.Usernotation used in the var declaration never triggers a compiler error, so I'm assuming the notation just isn't supported yet in the context of declaring an extension.Fortunately, there's a (somewhat cumbersome) work-around, which is to create two separate files, one for each module. Within each file import just that one module, and create a typealias for each clashing name using package-qualified name of the type.
For example, here's the relevant part of my
AppleTartTypeDisambiguation.swiftfile:And here's my
LegacyStoreTypeDisambiguation.swiftfile:I can then use the typealiases to extend either type. For example, here's how I successfully extended
AppleTart.User:After circulating the problem above to the Swift-Users mailing list, @belkadan reached out with a (correct) hunch that the underlying problem was that I have a type that has the same name as the module.
In fact, the
AppleTartmodule contained a type also namedAppleTart, which acts as an interface for controlling the framework that vends the module. I renamed the type toAppleTartFrameworkand am no longer experiencing the problem.swift-ci commentedon Sep 24, 2018
Comment by Vladimir Shabanov (JIRA)
Please fix. There are problems with importing custom obj-c error classes (descendants of NSError) even from single custom Obj-C framework to Swift app.
lilyball commentedon Feb 4, 2021
Also see SR-14142 where this missing language feature is causing emitted swiftinterface files to fail to compile.
Nest SocketAddress in NIOHTTPServer (#47)
4 remaining items
AnthonyLatsis commentedon Jan 28, 2026
Swift evolution proposal: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0491-module-selectors.md.
tshortli commentedon May 13, 2026
This was addressed by #87132.
x.Typeforcesxto be considered a type name #78988 as a duplicate of this issue