# How to properly reference a type and module with the same name?

**URL:** <https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964>\
**Category:** Swift-DocC\
**Created:** [March 15, 2022, 6:09pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964 "2022-03-15T18:09:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_Heck](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joseph_heck/32/22369_2.png) [@Joseph\_Heck](https://forums.swift.org/u/Joseph_Heck)\
**Post date:** [March 15, 2022, 6:09pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/1 "2022-03-15T18:09:48Z")

</div>

I haven't yet "learned" to shy away from the apparent complication of making a swift module that has a struct with the exact same name as the module. Prior to swift 5.6, I found that if I referenced the name with ```ModuleName``` as the symbol in the module documentation, it renders acceptably, and I could still reference the underlying struct with the same name using the symbols reference from the module down to the struct ```ModuleName/StructName```.

As a specific example: [https://github.com/heckj/CameraControlARView:](https://github.com/heckj/CameraControlARView:)```CameraControlARView``` is the name of the module, and when I want to reference the struct that has the same name, I use ```CameraControlARView/CameraControlARView```.

WIth Swift 5.6 released (using Xcode Version 13.3 (13E113)), I went to rebuild the docs and noticed a warning in that top-level documentation file for the module:  
`Redeclaration of 'CameraControlARView.md'; this file will be skipped.` While file it regarded as duplicate also seemed to change (sometimes the module, sometimes the struct) when I was invoking the build through Xcode.

Is there a "right way" to handle the scenario where I have a symbol with the same name as the module? (aside from never using a struct or class with the same name as your module?)

---

<div class="post-metadata">

**Author:** ![ethankusters](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ethankusters/32/19078_2.png) [@ethankusters](https://forums.swift.org/u/ethankusters)\
**Post date:** [March 15, 2022, 7:28pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/2 "2022-03-15T19:28:28Z")

</div>

Hi Joseph!

> [@Joseph\_Heck](#):
>
> Prior to swift 5.6, I found that if I referenced the name with `ModuleName` as the symbol in the module documentation, it renders acceptably, and I could still reference the underlying struct with the same name using the symbols reference from the module down to the struct `ModuleName/StructName` .

This should still hold true in Swift 5.6.

> [@Joseph\_Heck](#):
>
> `Redeclaration of 'CameraControlARView.md'; this file will be skipped.` While file it regarded as duplicate also seemed to change (sometimes the module, sometimes the struct) when I was invoking the build through Xcode.

I think you're seeing this because there are two files in your DocC catalog named `CameraControlARView.md`:

- [`Documentation.docc/CameraControlARView.md`](https://github.com/heckj/CameraControlARView/blob/main/Sources/CameraControlARView/Documentation.docc/CameraControlARView.md)
- [`Documentation.docc/Extensions/CameraControlARView.md`](https://github.com/heckj/CameraControlARView/blob/main/Sources/CameraControlARView/Documentation.docc/Extensions/CameraControlARView.md)

Because articles in Swift-DocC are linked to via their file name (not file path), `docc` raises an error upon encountering multiple articles with the same name. However, in your case, you have two documentation extensions with the same file name so I don't think this should cause an error - I would view this is a bug in Swift-DocC's diagnostics.

As a workaround, you could name the second documentation extension something like `CameraControlARView.CameraControlARView.md` and I _think_ you'll see that diagnostic go away. But a bug on [bugs.swift.org](http://bugs.swift.org) for documentation extensions with equal file names would be great as well.

- Ethan

---

<div class="post-metadata">

**Author:** ![Joseph\_Heck](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joseph_heck/32/22369_2.png) [@Joseph\_Heck](https://forums.swift.org/u/Joseph_Heck)\
**Post date:** [March 15, 2022, 8:24pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/3 "2022-03-15T20:24:56Z")

</div>

Ahh!! thank you @ethankusters - I'd never made the mental link that an extension page was basically mapped identically to articles since they're called separate things in the templates. As you suggested, renaming the extension page worked perfectly and resolved the warning scenario.

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [March 15, 2022, 8:44pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/4 "2022-03-15T20:44:56Z")

</div>

is there a reason the explicit module name is required?

---

<div class="post-metadata">

**Author:** ![Joseph\_Heck](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joseph_heck/32/22369_2.png) [@Joseph\_Heck](https://forums.swift.org/u/Joseph_Heck)\
**Post date:** [March 15, 2022, 8:59pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/5 "2022-03-15T20:59:37Z")

</div>

(Not sure if I'm quite understanding what you're asking)

For the top-level module documentation in the catalog, I think the symbol that matched the module name _was_ required. Without it in place, regardless of the name of the file itself, the content isn't mapped to match the top level of the documentation. (for example, in [CameraControlARView/CameraControlARView.md at main · heckj/CameraControlARView · GitHub](https://github.com/heckj/CameraControlARView/blob/main/Sources/CameraControlARView/Documentation.docc/CameraControlARView.md) if you clip out line `1` and build the docs, the module will appear in the docs as a "No overview available".

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [March 15, 2022, 9:08pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/6 "2022-03-15T21:08:42Z")

</div>

oh, got it. `swift-biome` uses package names to solve this problem. right now, every package in the biome starts with `swift-`, and the hyphen cannot appear in a swift identifier, so it is unambiguous. at some point i’m planning on migrating to an “absolute path” scheme where `/foomodule` always stands for `FooModule`.

---

<div class="post-metadata">

**Author:** ![Joseph\_Heck](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joseph_heck/32/22369_2.png) [@Joseph\_Heck](https://forums.swift.org/u/Joseph_Heck)\
**Post date:** [March 15, 2022, 9:11pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/7 "2022-03-15T21:11:29Z")

</div>

Makes sense - and I've seen a number of projects have that pattern - especially when they're supporting more than one language (automerge-swift comes to mind), or just have a different name for the module than anything within that module. I knew it was supported, but I completely recognize that I made things harder on myself by not having a different module name for this quickie thing.

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [March 15, 2022, 9:14pm UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/8 "2022-03-15T21:14:19Z")

</div>

> [@Joseph\_Heck](#):
>
> but I completely recognize that I made things harder on myself by not having a different module name for this quickie thing.

for what it’s worth, [`swift-json`](https://github.com/kelvin13/swift-json), [`swift-grammar`](https://github.com/kelvin13/swift-grammar), [`swift-png`](https://github.com/kelvin13/swift-png), and [`jpeg`](https://github.com/kelvin13/jpeg) all have this problem too. it’s more of a problem for `jpeg` because it doesn’t have the `swift-` prefix.

this is part of the reason i’m putting so much effort into [`swift-biome`](https://github.com/kelvin13/swift-biome)’s URI resolution algorithm.

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [April 20, 2022, 12:43am UTC](https://forums.swift.org/t/how-to-properly-reference-a-type-and-module-with-the-same-name/55964/9 "2022-04-20T00:43:43Z")

</div>

> [@ethankusters](#):
>
> > [@Joseph\_Heck](#):
> >
> > Prior to swift 5.6, I found that if I referenced the name with `ModuleName` as the symbol in the module documentation, it renders acceptably, and I could still reference the underlying struct with the same name using the symbols reference from the module down to the struct `ModuleName/StructName` .
> 
> This should still hold true in Swift 5.6.

coming back to this, isn’t this behavior the opposite of how name resolution [usually works](https://bugs.swift.org/browse/SR-898) in swift?

```swift
import Foo

// error: 'Foo' is not a member type of enum 'Foo.Foo'
var foo:Foo.Foo 
{
}

```

moreover, if the module `Foo` contains a type named `Foo`, it should also be impossible to reference any of the other symbols in `Foo` with a module-qualified name:

```swift
import Foo

// error: 'Bar' is not a member type of enum 'Foo.Foo'
var bar:Foo.Bar 
{
}

```
