# Contradictory nonisolated actor Foo {} syntax

**URL:** <https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905>\
**Category:** Using Swift\
**Created:** [October 28, 2025, 10:53am UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905 "2025-10-28T10:53:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_l](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@Jeff\_l](https://forums.swift.org/u/Jeff_l)\
**Post date:** [October 28, 2025, 10:53am UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/1 "2025-10-28T10:53:46Z")

</div>

I am trying to understand why the below syntax is valid. It seems contradictory, but the code compiles, and it appears to behave as if `nonisolated` is not present.

```swift
nonisolated actor Counter {

    var counter = 0

    func increment() {
        counter += 1
    }
}

```

I tested the above and `await` is still required to call `increment` and I don’t see any race conditions when I ran multiple iterations.

---

<div class="post-metadata">

**Author:** ![jamieQ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jamieq/32/5117_2.png) [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Post date:** [October 28, 2025, 11:11am UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/2 "2025-10-28T11:11:38Z")

</div>

hi, and welcome to the swift forums! i believe this is pretty clearly a bug – this used to be rejected in the Swift 6.0 compiler, but began being accepted in 6.1 (see this [example](https://swift.godbolt.org/z/f6chj93E4)). i would recommend [filing a bug report](https://github.com/swiftlang/swift/issues/new?template=bug-report.yml).

* * *

as an aside, it seems like there are numerous related issues with various attributes being erroneously accepted on `actor`s when they presumably should not be ([exhibit A](https://github.com/swiftlang/swift/issues/85134), [exhibit B](https://github.com/swiftlang/swift/pull/85170)).

---

<div class="post-metadata">

**Author:** ![Jeff\_l](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@Jeff\_l](https://forums.swift.org/u/Jeff_l)\
**Post date:** [October 28, 2025, 12:09pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/3 "2025-10-28T12:09:05Z")

</div>

Thank you. As suggested, I have filed a [bug](https://github.com/swiftlang/swift/issues/85174).

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [October 28, 2025, 12:14pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/4 "2025-10-28T12:14:47Z")

</div>

> [@jamieQ](#):
>
> as an aside, it seems like there are numerous related issues with various attributes being erroneously accepted on `actor`s when they presumably should not be ([exhibit A](https://github.com/swiftlang/swift/issues/85134), [exhibit B](https://github.com/swiftlang/swift/pull/85170)).

Since an `actor` is just a ClassDecl under the hood, the compiler will accept any attribute that is allowed on a `class`, even though some might not be meaningful with an actor. Someone needs to go through and ensure anything meaningless (like `open`, `final`, and `nonisolated`) is properly rejected in this case.

---

<div class="post-metadata">

**Author:** ![CrystDragon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/crystdragon/32/10461_2.png) [@CrystDragon](https://forums.swift.org/u/CrystDragon)\
**Post date:** [October 28, 2025, 12:27pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/5 "2025-10-28T12:27:35Z")

</div>

> [@Jeff\_l](#):
>
> and it appears to behave as if `nonisolated` is not present.  
> ...  
> I tested the above and `await` is still required to call `increment` and I don’t see any race conditions when I ran multiple iterations.

We can draw the same conclusion by just looking at `var counter = 0`, because it's illegal to write `nonisolated var` in an `actor`.

---

<div class="post-metadata">

**Author:** ![jamieQ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jamieq/32/5117_2.png) [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Post date:** [October 28, 2025, 12:33pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/6 "2025-10-28T12:33:12Z")

</div>

> Since an `actor` is just a ClassDecl under the hood, the compiler will accept any attribute that is allowed on a `class` , even though some might not be meaningful with an actor.

yes, i assume many of the issues here stem from the fact that actors piggy-back off of 'normal' classes for some (most?) of their implementation. that, plus the fact that in some of the initial design pitches/proposals/prototypes it seems like `actor` was being considered as potentially something of a kind of '`class` modifier' rather than becoming more of its own 'category of thing' (IIUC, `actor class` or some such used to be valid syntax in an implementation prototype at some point).

it's unfortunate that these inconsistent/meaningless declarations weren't more aggressively rejected since apparently failure to do so may lead to runtime issues in some cases (see 'exhibit A' from above), and it also makes it more painful to fix due to source breaks. but i guess that's how it goes sometimes.

---

<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:** [October 28, 2025, 12:34pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/7 "2025-10-28T12:34:18Z")

</div>

> [@Slava\_Pestov](#):
>
> like `open`, `final`, and `nonisolated`

`MainActor` is annotated `final`, is there a good reason for this? Would it be in any way breaking (e.g. changing mangling) to remove `final` here?

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [October 28, 2025, 12:57pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/8 "2025-10-28T12:57:51Z")

</div>

> [@jamieQ](#):
>
> and it also makes it more painful to fix due to source breaks. but i guess that's how it goes sometimes.

Yeah, the way the compiler is architected, anything not explicitly rejected, is accepted. It would be better if it was the other way around but I don’t know if that’s possible to do in a systemic way.

---

<div class="post-metadata">

**Author:** ![jamieQ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jamieq/32/5117_2.png) [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Post date:** [October 28, 2025, 1:45pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/9 "2025-10-28T13:45:09Z")

</div>

> [@bbrk24](#):
>
> `MainActor` is annotated `final`, is there a good reason for this? Would it be in any way breaking (e.g. changing mangling) to remove `final` here?

the attribute was added in [this PR](https://github.com/swiftlang/swift/pull/36878), and there is some discussion about it in the comments (well, some related-sounding things at any rate; though i can't say i follow it all). there's also some discussion about it in this pitch thread for custom executors (Chris & John discussion starting [here](https://forums.swift.org/t/support-custom-executors-in-swift-concurrency/44425/35)).

the `final` attribute is marked as `ABIBreakingToAdd | ABIBreakingToRemove` in [this source file](https://github.com/swiftlang/swift/blob/ca0491ac77c4c4be4436f6841ce8e70df91c9b8a/include/swift/AST/DeclAttr.def#L76), which suggests it can't necessarily be freely adopted/dropped. additionally the output of [this godbolt example](https://swift.godbolt.org/z/a5aPjnja1) suggests its presence may impact type metadata and descriptors.

---

<div class="post-metadata">

**Author:** ![tshortli](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tshortli/32/15850_2.png) [@tshortli](https://forums.swift.org/u/tshortli)\
**Post date:** [October 28, 2025, 4:30pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/10 "2025-10-28T16:30:33Z")

</div>

`final` is not meaningless on `actor`, unfortunately. When actors were first introduced, the door was left open to potentially amend the language to allow them to be subclassed. That has not happened and probably never will, but the ABI for method calls on actors go through dynamic dispatch in case there's actually a subclass present at runtime. That means that marking an actor method `final`, or marking the whole actor `final`, changes the ABI of calling methods on the actor since calls will no longer go through dynamic dispatch. There probably are other attributes that we can start rejecting on `actor` declarations, but I don't think `final` is one of them.

---

<div class="post-metadata">

**Author:** ![jamieQ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jamieq/32/5117_2.png) [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Post date:** [October 28, 2025, 4:47pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/11 "2025-10-28T16:47:03Z")

</div>

thank you for the clarifications and additional context Allan! i need to read up on the difference b/w `public` and `public final` to better understand what the implications of this are... but it seems unfortunate if developers need to explicitly write `final` on these types to opt out of dynamic dispatch, when that attribute is at least implied to be inapplicable/implicit in various ways (e.g. like when you try to make one `actor` inherit from another and it fails). i was thinking perhaps this could be phased out with a warning now + error later, but if there are ABI implications, that's presumably a less straightforwardly plausible option. perhaps there's still something that could be done though... 🤔

* * *

fluff: this is how i read this :)

> When actors were first introduced, the door was left `open` to potentially amend the language to allow them to be subclassed.

---

<div class="post-metadata">

**Author:** ![dima\_kozhinov](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dima\_kozhinov](https://forums.swift.org/u/dima_kozhinov)\
**Post date:** [October 28, 2025, 5:24pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/12 "2025-10-28T17:24:35Z")

</div>

Probably actors should have been structs under the hood.

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [October 28, 2025, 5:36pm UTC](https://forums.swift.org/t/contradictory-nonisolated-actor-foo-syntax/82905/13 "2025-10-28T17:36:00Z")

</div>

> [@dima\_kozhinov](#):
>
> Probably actors should have been structs under the hood.

Actors as commonly imagined across programming languages have identity, almost by definition. If Swift had something called an "actor" that was a value type, it would probably cause too much confusion, even if it made sense as a feature in itself.
