Skip to content

class_delegate_protocol false positive when using & #5982

@Deanosaurus

Description

@Deanosaurus

New Issue Checklist

Bug Description

When declaring a protocol SwiftLint generates a false-positive for a class_delegate_protocol violation when AnyObject is added via &.

/// "Class Delegate Protocol Violation: Delegate protocols should be class-only so they can be weakly referenced (class_delegate_protocol)"
protocol SomeDelegate: AnyObject & Sendable {

}

/// No error.
protocol SomeDelegate: AnyObject, Sendable {

}

I realize technically speaking AnyObject & Sendable is technically a different type than independently AnyObject and Sendable, but the principle the rule is trying to get at should resolve the same.

Command/Output

$ swiftlint --strict

Class Delegate Protocol Violation: Delegate protocols should be class-only so they can be weakly referenced (class_delegate_protocol)

Environment

  • SwiftLint version: 0.57.0
  • Xcode version: 16.2.0
  • Installation method used: Homebrew
  • Configuration file: default

Are you using nested configurations? If so, paste their
relative paths and respective contents.

  • No nested config

Metadata

Metadata

Assignees

Labels

bugUnexpected and reproducible misbehavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions