# @warn\_unqualified\_access attribute name

**URL:** <https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778>\
**Category:** Discussion\
**Created:** [January 24, 2023, 10:57pm UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778 "2023-01-24T22:57:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradleymackey](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bradleymackey/32/24156_2.png) [@bradleymackey](https://forums.swift.org/u/bradleymackey)\
**Post date:** [January 24, 2023, 10:57pm UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778/1 "2023-01-24T22:57:26Z")

</div>

Hi everyone,

Following on from previous discussions around this topic ([~1 week ago](https://forums.swift.org/t/pitch-rename-public-snake-case-attributes-to-camelcase/62574), [~7 years ago](https://forums.swift.org/t/use-lowercamelcase-for-warn-unqualified-access-attribute/3753/6)), I'm hoping we can reach a consensus as to how to improve the `@warn_unqualified_access` attribute. My [original post](https://forums.swift.org/t/pitch-rename-public-snake-case-attributes-to-camelcase/62574) was created with the intention of simply converting this attribute to camelCase, but this was [reasonably pointed out](https://forums.swift.org/t/pitch-rename-public-snake-case-attributes-to-camelcase/62574/3) that this attribute could do with a more holistic review in isolation.

This is one attribute from the early days of Swift that was [never meant to be public](https://forums.swift.org/t/use-lowercamelcase-for-warn-unqualified-access-attribute/3753/3), but has since been adopted lightly over the years ([results on GitHub](https://github.com/search?p=1&q=%22%40warn_unqualified_access%22+language%3ASwift+extension%3Aswift+-path%3Atest%2Fattr+-path%3Aswift+-path%3Aswift-main+-path%3Aswift%2Fswift-main%2Ftest%2Fattr+-path%3Atest%2FIDE+-path%3AArray+-path%3Aswift%2Ftest%2FIDE+-path%3AArray%2FSwiftMain-Array%2FSwiftMain-Array%2Fswift-main%2Ftest%2Fattr+-path%3ASymbolExtractorAndRenamer%2Fswift%2Ftest%2Fattr+-path%3AHackingWithSwift++-path%3Avalidation-test+language%3ASwift+language%3ASwift&type=Code)). Having never been through Evolution and a Swift 6 language mode in full development (offering the rare opportunity for a source-breaking change), it's a perfect time to evaluate this attribute.

As I see it, we have a few options:

1. Update the name of the attribute to camelCase for consistency with other attributes (e.g. `@warnUnqualifiedAccess`) or improve the naming for improved left-to-right readability (e.g. `@unqualifiedAccessWarning`), optionally parameterizing to allow for future extensibility (e.g. `@unqualifiedAccess(warning)`).
2. Demote this to a private attribute (`@_warn_unqualified_access`), and remove it from public documentation.
3. Do nothing.

I personally think **1** seems like the most sensible direction for this attribute, introduced in a Swift 6 language mode. The attribute is lightly used but a useful feature to have for potentially ambiguous APIs. I'd also champion the spelling `@unqualifiedAccess(warning)` for the improved clarity and would easily allow for the obvious extension of `@unqualifiedAccess(error)`.

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [January 24, 2023, 11:02pm UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778/2 "2023-01-24T23:02:50Z")

</div>

> [@bradleymackey](#):
>
> This is one attribute from the early days of Swift that was [never meant to be public](https://forums.swift.org/t/use-lowercamelcase-for-warn-unqualified-access-attribute/3753/3), but has since been adopted lightly over the years ([results on GitHub](https://github.com/search?q=warn_unqualified_access&type=code)).

All the uses I can see from the first two pages of that search seem to be forks of, modifications of, or didactic materials related to the Swift compiler, not 'adoption' as in a third-party API that makes use of it.

---

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [January 24, 2023, 11:06pm UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778/3 "2023-01-24T23:06:21Z")

</div>

Try filtering the language to Swift - [results](https://github.com/search?q=warn_unqualified_access+language%3ASwift&type=code&l=Swift).

There are a handful of projects using it, it seems.

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [January 24, 2023, 11:14pm UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778/4 "2023-01-24T23:14:10Z")

</div>

> [@Karl](#):
>
> There are a handful of projects using it, it seems.

Still mostly just test cases.

Deep in the search pages there are a few organic uses I can see, the purpose of which I'm not clear on as they're decorating APIs which almost certainly do not clash with top-level function names and, for that matter, decorate all or almost all APIs in the project. I suppose it could be some sort of attempt at forcing end users to always write `self.` when using their types, but I am not sure why we want or need to support that.

---

<div class="post-metadata">

**Author:** ![bradleymackey](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bradleymackey/32/24156_2.png) [@bradleymackey](https://forums.swift.org/u/bradleymackey)\
**Post date:** [January 24, 2023, 11:14pm UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778/5 "2023-01-24T23:14:26Z")

</div>

Apologies, that was not a good example. I've updated the link to remove a lot of compiler-fork-based results. Usage of the attribute appears to be _very light indeed_.

---

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [January 24, 2023, 11:30pm UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778/6 "2023-01-24T23:30:13Z")

</div>

Well, I'm not sure how GitHub sorts these things, so the position of results in the list may not be relevant.

Also, it's worth keeping in mind that lots of Swift code (particularly for things like iOS applications) is not available on GitHub, so we can only glean so much from what we find there.

Personally, I think this attribute is useful, but in very, very niche situations. I think I've only ever used it once, years ago, and I can't even remember what for. I'm not surprised we don't find many instances of it in the wild, but I also don't see reason to remove it or "demote" it 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![bbrk24](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bbrk24/32/27370_2.png) [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Post date:** [January 25, 2023, 5:28pm UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778/7 "2023-01-25T17:28:26Z")

</div>

I’ve run into a case where I wanted to use this but couldn’t.

```swift
struct S {
    // @warn_unqualified_access
    var type: Any.Type

    func foo(x: Any) {
        let dynamicType = type(of: x)
        // interpreted as self.type.init(of:) rather than Swift.type(of:). Compile error since no such init exists
    }
}

```

Since it only applies to methods and not properties, I couldn’t put the warning there.

---

<div class="post-metadata">

**Author:** ![hooman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hooman/32/43536_2.png) [@hooman](https://forums.swift.org/u/hooman)\
**Post date:** [January 26, 2023, 6:53am UTC](https://forums.swift.org/t/warn-unqualified-access-attribute-name/62778/8 "2023-01-26T06:53:08Z")

</div>

Here is one possible use case:

> [@In SwiftUI.View body, accidentally put \`padding()\` (all by itself, no dot in front): it compiles fine, but preview doesn't work/run show blank screen or crash](https://forums.swift.org/t/in-swiftui-view-body-accidentally-put-padding-all-by-itself-no-dot-in-front-it-compiles-fine-but-preview-doesnt-work-run-show-blank-screen-or-crash/38452/8):
>
> Here is a short sample code to show what is happening. Note that the only difference between bar() and baz() is the dot before foo(). The solution for catching such errors is using @warn\_unqualified\_access attribute as indicated in the comments: protocol P { func foo() } struct S1: P { func foo() { print("S1 foo()") } } struct S2: P { var s1 = S1() // Uncomment the following to get a warning: //@warn\_unqualified\_access func foo() { print("S2 foo()") } func b…
