Redundant Final

final is redundant

  • Identifier: redundant_final
  • Enabled by default: No
  • Supports autocorrection: Yes
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Rationale

Actors in Swift currently do not support inheritance, making final redundant on both actor declarations and their members. Note that this may change in future Swift versions if actor inheritance is introduced.

Additionally, final is redundant on members of a final class since they cannot be overridden.

Non Triggering Examples

actor MyActor {}
final class MyClass {}
@globalActor
actor MyGlobalActor {}
actor MyActor {
    func doWork() {}
    final class C1 {}
    class C2 {
        final func doWork() {}
    }
}
class MyClass {
    final func doWork() {}
}

Triggering Examples

final actor MyActor {}
public final actor DataStore {}
@globalActor
final actor MyGlobalActor {}
actor MyActor {
    final func doWork() {}
}
actor MyActor {
    final var value: Int { 0 }
}
final class C1 {
    final actor A1 {
        final func doWork() {}
    }
    final func doWork() {}
    final class C2 {
        final func doWork() {}
    }
}