Skip to content

[SR-7495] Checking protocol conformance doesn't work #50038

@swift-ci

Description

@swift-ci
Previous ID SR-7495
Radar None
Original Reporter domas (JIRA User)
Type Bug
Status Resolved
Resolution Won't Do
Environment

Xcode 9.3 (9E145)
Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0
macOS 10.13.4 (17E199)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 723173a88503687fffbeb4aa3a8c991c

Issue Description:

Trying to check if type conforms to a protocol in an indirect way fails.

protocol P {}
struct T: P {}

// 0. Check with `is`
T.self is P.Type // true

// 1. Direct conformance check
func isOfTypeP(_ t: Any.Type) -> Bool {
    P.self // __lldb_expr_67.P.Protocol
    return t is P.Type
}
isOfTypeP(T.self) // true
 
// 2. Indirect conformance check
func isType<G>(_ t: Any.Type, subtypeOf _: G.Type) -> Bool {
    G.self // __lldb_expr_67.P.Protocol
    return t is G.Type
}
isType(T.self, subtypeOf: P.self) // false!!

Checking the superclass in the same way works as expected.

class S {}
class C: S {}

isType(C.self, subtypeOf: S.self) // true

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions