# ~Copyable and @dynamicmemberlookup

**URL:** <https://forums.swift.org/t/copyable-and-dynamicmemberlookup/68426>\
**Category:** Compiler\
**Tags:** noncopyable\
**Created:** [November 13, 2023, 1:05pm UTC](https://forums.swift.org/t/copyable-and-dynamicmemberlookup/68426 "2023-11-13T13:05:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvsrvs](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rvsrvs/32/5270_2.png) [@rvsrvs](https://forums.swift.org/u/rvsrvs)\
**Post date:** [November 13, 2023, 1:05pm UTC](https://forums.swift.org/t/copyable-and-dynamicmemberlookup/68426/1 "2023-11-13T13:05:48Z")

</div>

Playing around with wrapping some of my value types in noncopyable types generated the following in a playground under Xcode 15.1b2:

```swift
struct A { }
let a = A()

@dynamicMemberLookup
struct Ref<S>: ~Copyable {
    var value: S
    subscript<T>(dynamicMember keyPath: KeyPath<S, T>) -> T {
        value[keyPath: keyPath]
    }
}
let refA = Ref(value: a)

```

This produces:

```swift
error: couldn't IRGen expression. Please enable the expression log by running "log enable lldb expr", then run the failing expression again, and file a bug report with the log output.

```

Not quite sure a) how to do that last step or b) if this is supposed to work at this point. Thoughts?

---

<div class="post-metadata">

**Author:** ![rvsrvs](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rvsrvs/32/5270_2.png) [@rvsrvs](https://forums.swift.org/u/rvsrvs)\
**Post date:** [November 13, 2023, 2:13pm UTC](https://forums.swift.org/t/copyable-and-dynamicmemberlookup/68426/2 "2023-11-13T14:13:14Z")

</div>

ok, weird behavior from a playground. Here's a more precise version from trying to compile as a command line tool on Mac:

```swift
struct A { var a: String }

@dynamicMemberLookup
struct Ref<S>: ~Copyable {
    var value: S
    init(value: S) {
        self.value = value
    }
    subscript<T>(dynamicMember keyPath: KeyPath<S, T>) -> T {
        value[keyPath: keyPath]
    }
}

let a = A(a: "Yo")
let refA = Ref(value: a)
_ = refA.value.a
_ = refA.value[keyPath: \.a]
_ = refA.a

print("hello, world!")

```

The line using the dynamicMember produces:

```swift
Copy of noncopyable typed value. This is a compiler bug. Please file a bug with a small example of the bug

```

Is this supposed to work yet?

---

<div class="post-metadata">

**Author:** ![scanon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scanon/32/2445_2.png) [@scanon](https://forums.swift.org/u/scanon)\
**Post date:** [November 13, 2023, 3:03pm UTC](https://forums.swift.org/t/copyable-and-dynamicmemberlookup/68426/3 "2023-11-13T15:03:58Z")

</div>

Whether or not it's "supposed to work yet," it's worth a bug report. Any internal compiler diagnostic merits a bug report.

In this case, it appears to work on the nightly, so I think this has been fixed since 5.9 was cut? [Compiler Explorer](https://godbolt.org/z/sP63YsM97)

CC @Joe_Groff @kavon
