# Actor property is treated as nonisolated from within module but treated as isolated from outside module

**URL:** <https://forums.swift.org/t/actor-property-is-treated-as-nonisolated-from-within-module-but-treated-as-isolated-from-outside-module/62685>\
**Category:** Using Swift\
**Tags:** module, property, actors, nonisolated\
**Created:** [January 20, 2023, 10:50am UTC](https://forums.swift.org/t/actor-property-is-treated-as-nonisolated-from-within-module-but-treated-as-isolated-from-outside-module/62685 "2023-01-20T10:50:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremyabannister](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jeremyabannister/32/10143_2.png) [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Post date:** [January 20, 2023, 10:50am UTC](https://forums.swift.org/t/actor-property-is-treated-as-nonisolated-from-within-module-but-treated-as-isolated-from-outside-module/62685/1 "2023-01-20T10:50:16Z")

</div>

I the below a known bug? Or it is expected behavior? It seems like a bug to me, but maybe I'm wrong.

```swift
// ModuleA

public actor Foo {
    public let bar: Int = 7
}

```

```swift
// ModuleB

import ModuleA

func demo (foo: Foo) {
    print(foo.bar) // Error: Actor-isolated property 'someNumber' can not be referenced from a non-isolated context
}

```

If I move `demo(foo:)` to `ModuleA` then it compiles.

---

<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 20, 2023, 2:21pm UTC](https://forums.swift.org/t/actor-property-is-treated-as-nonisolated-from-within-module-but-treated-as-isolated-from-outside-module/62685/2 "2023-01-20T14:21:53Z")

</div>

> [@jeremyabannister](#):
>
> If I move `demo(foo:)` to `ModuleA` then it compiles.

…with full concurrency warnings turned on?

---

<div class="post-metadata">

**Author:** ![jeremyabannister](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jeremyabannister/32/10143_2.png) [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Post date:** [January 20, 2023, 2:36pm UTC](https://forums.swift.org/t/actor-property-is-treated-as-nonisolated-from-within-module-but-treated-as-isolated-from-outside-module/62685/3 "2023-01-20T14:36:54Z")

</div>

I'm not sure - I'm using Xcode 14.2 basically as it comes out of the box. I haven't deliberately modified anything like that. I get (and avoid) plenty of concurrency warnings, so they're certainly not turned all the way off.

---

<div class="post-metadata">

**Author:** ![Jumhyn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jumhyn/32/3891_2.png) [@Jumhyn](https://forums.swift.org/u/Jumhyn)\
**Post date:** [January 20, 2023, 2:40pm UTC](https://forums.swift.org/t/actor-property-is-treated-as-nonisolated-from-within-module-but-treated-as-isolated-from-outside-module/62685/4 "2023-01-20T14:40:23Z")

</div>

This is allowed by [SE-0306](https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md#actor-isolation):

> First, a cross-actor reference to immutable state is allowed from anywhere in the same module as the actor is defined because, once initialized, that state can never be modified (either from inside the actor or outside it), so there are no data races by definition.

We have to disallow it across modules because we don’t publicly expose the fact that a read-only piece of state is a `let` as opposed to a computed `var` or `private(set) var`.

---

<div class="post-metadata">

**Author:** ![jeremyabannister](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jeremyabannister/32/10143_2.png) [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Post date:** [January 20, 2023, 2:42pm UTC](https://forums.swift.org/t/actor-property-is-treated-as-nonisolated-from-within-module-but-treated-as-isolated-from-outside-module/62685/5 "2023-01-20T14:42:36Z")

</div>

But evidently we do publicly expose if I put a `nonisolated` on the property, because that allows the function to compile inside of ModuleB. Couldn't we publicly mark `let` properties as `nonisolated` as if they were explicitly marked as such, but just not requiring the library developer to write a redundant word?

---

<div class="post-metadata">

**Author:** ![Jumhyn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jumhyn/32/3891_2.png) [@Jumhyn](https://forums.swift.org/u/Jumhyn)\
**Post date:** [January 20, 2023, 2:48pm UTC](https://forums.swift.org/t/actor-property-is-treated-as-nonisolated-from-within-module-but-treated-as-isolated-from-outside-module/62685/6 "2023-01-20T14:48:10Z")

</div>

Yes, `nonisolated` is part of the (public) API contract for your type. Making `let` imply `nonisolated` means that it wouldn’t be possible to change a `let` to later be `nonisolated` and/or mutable in a source-compatible way. There’s further discussion in the alternatives considered section [here](https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md#cross-actor-lets).
