# AttributedString literal?

**URL:** <https://forums.swift.org/t/attributedstring-literal/85064>\
**Category:** Using Swift\
**Tags:** string, literals, attributedstring\
**Created:** [March 1, 2026, 6:44am UTC](https://forums.swift.org/t/attributedstring-literal/85064 "2026-03-01T06:44:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [March 1, 2026, 6:44am UTC](https://forums.swift.org/t/attributedstring-literal/85064/1 "2026-03-01T06:44:36Z")

</div>

```swift
"nam" + "e\u{0301}"

```

This is supposed to be equivalent to a single-piece string literal. But my code:

```swift
let decomposedLiteral: NameToken = "nam" + "e\u{0301}"

```

Had an error of “Cannot convert value of type 'AttributedString' to specified type 'NameToken'“. Using an actual one-piece literal:

```swift
let decomposedLiteral: NameToken = "name\u{0301}"

```

worked. Why was that literal expression considered an `AttributedString`? The code was part of a test for `NameToken`'s`ExpressibleByStringLiteral`use.

---

<div class="post-metadata">

**Author:** ![Andropov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/andropov/32/35955_2.png) [@Andropov](https://forums.swift.org/u/Andropov)\
**Post date:** [March 1, 2026, 12:24pm UTC](https://forums.swift.org/t/attributedstring-literal/85064/3 "2026-03-01T12:24:26Z")

</div>

> [@CTMacUser](#):
>
> ```swift
> "nam" + "e\u{0301}"
> 
> ```
> 
> This is supposed to be equivalent to a single-piece string literal.

AFAIK you can't build a string _literal_ like that. String literals need to be known at compile time, so Swift would need to know the result of `"nam" + "e\u{0301}"` at compile time.

In order to do that, it'd need to apply the [`+(_:,_:)` operator](https://developer.apple.com/documentation/swift/string/+(_:_:)) (which is just a "regular" Swift function) to the two `"nam"` and `"e\u{0301}"` arguments. And Swift can't do that kind of compile-time execution yet.

(Actually, the type checker would need to be able to execute at compile time any other `+(_:,_;)` operator that can be applied on `String`/`StringLiteral` arguments!).

* * *

As to why the result of `"nam" + "e\u{0301}"` is inferred to be `AttributedString` instead of `String` in your code: it must be because of something else in the surrounding code. A minimal example isn't inferred to be `AttributedString`:

```swift
struct Foo: ExpressibleByStringLiteral {
    init(stringLiteral value: StringLiteralType) {}
}

let foo: Foo = "nam" + "e\u{0301}" // ❌ Cannot convert value of type 'String' to specified type 'Foo'

```

---

<div class="post-metadata">

**Author:** ![ksluder](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@ksluder](https://forums.swift.org/u/ksluder)\
**Post date:** [March 2, 2026, 5:21pm UTC](https://forums.swift.org/t/attributedstring-literal/85064/4 "2026-03-02T17:21:35Z")

</div>

> [@CTMacUser](#):
>
> ```swift
> "nam" + "e\u{0301}"
> 
> ```
> 
> This is supposed to be equivalent to a single-piece string literal.

By definition, an expression is not a literal.
