Skip to content

Compiler Incorrectly Allows Protocol Methods on __kindof Type When Protocol is Visible #11776

@tripleCC

Description

@tripleCC

Description:
The Clang compiler incorrectly allows sending protocol-defined messages to __kindof types when the protocol is visible in the current scope, even if the base type doesn't conform to that protocol.

Steps to Reproduce:

  1. Case A (Incorrect Behavior):

    @protocol A <NSObject>
    - (void)aaa;
    @end
    
    __kindof UIView *v;
    [v aaa]; // Compiles without error (UNEXPECTED)

    Actual Result: Compilation succeeds despite UIView not conforming to protocol A.

  2. Case B (Correct Behavior):

    __kindof UIView *v;
    [v aaa]; // Compiler error (EXPECTED)

    Actual Result: Properly errors with No known instance method for selector 'aaa'.

Expected Behavior:
Both cases should fail compilation with No known instance method for selector 'aaa' since:

  • __kindof UIView * represents UIView or its subclasses
  • UIView doesn't implement -aaa
  • Protocol visibility shouldn't affect method availability for unrelated types

Impact:
Creates false sense of type safety with __kindof when unrelated protocols are visible, potentially leading to runtime crashes.

Environment:

  • Clang version: [16.0.0]
  • Xcode: 16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions