Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6304] Wrong type check results about Type and Value #48854

Open
swift-ci opened this issue Nov 6, 2017 · 0 comments
Open

[SR-6304] Wrong type check results about Type and Value #48854

swift-ci opened this issue Nov 6, 2017 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Nov 6, 2017

Previous ID SR-6304
Radar None
Original Reporter tarunon (JIRA User)
Type Bug
Environment

Xcode
Version 9.1 (9B55)

Swift

Apple Swift version 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)

Target: x86_64-apple-macosx10.9

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

md5: 2c0cd9cf0b0ddbc83e4a2b1d8bf276b4

Issue Description:

import Foundation

// Make 5 pattern base types

class A {}
protocol B {}
protocol C: class {}
@objc protocol D {}
protocol E: NSObjectProtocol {}

// Make container protocol

protocol Container {
    associatedtype Wrapped
}

// If Container conforms to Wrapped then return true.
func typeCheckShouldBeSuccess<T: Container>(_ type: T.Type) -> Bool {
    return T.self is T.Wrapped.Type
}

// Always false because T.self is type and not conforms to value of Wrapped.
func typeCheckShouldBeFailure<T: Container>(_ type: T.Type) -> Bool {
    return T.self is T.Wrapped
}

// Make Container implementation that extends of base type, and Wrapped is base type.

class ContainerA: A, Container {
    typealias Wrapped = A
}
class ContainerB: B, Container {
    typealias Wrapped = B
}
class ContainerC: C, Container {
    typealias Wrapped = C
}
class ContainerD: D, Container {
    typealias Wrapped = D
}
class ContainerE: NSObject, E, Container {
    typealias Wrapped = E
}

// Case of A is fine.

let r01 = ContainerA.self is ContainerA.Wrapped.Type    // true. ContainerA is subclass of A
let r02 = typeCheckShouldBeSuccess(ContainerA.self)     // true. Should be same of r01
let r03 = ContainerA.self is ContainerA.Wrapped         // false. ContainerA.self is Type, not value of A.
let r04 = typeCheckShouldBeFailure(ContainerA.self)     // false. Should be same of r03

// Cases of B~E are (maybe) wrong.

let r05 = ContainerB.self is ContainerB.Wrapped.Type    // true. ok.
let r06 = typeCheckShouldBeSuccess(ContainerB.self)     // false. wrong. It should be same of r05.
let r07 = ContainerB.self is ContainerB.Wrapped         // false. ok.
let r08 = typeCheckShouldBeFailure(ContainerB.self)     // false. ok.

let r09 = ContainerC.self is ContainerC.Wrapped.Type    // true. ok.
let r10 = typeCheckShouldBeSuccess(ContainerC.self)     // false. wrong. It should be same of r09.
let r11 = ContainerC.self is ContainerC.Wrapped         // false. ok.
let r12 = typeCheckShouldBeFailure(ContainerC.self)     // true. wrong. It should be same of r11.

let r13 = ContainerD.self is ContainerD.Wrapped.Type    // true. ok.
let r14 = typeCheckShouldBeSuccess(ContainerD.self)     // false. wrong. It should be same of r13.
let r15 = ContainerD.self is ContainerD.Wrapped         // true. wrong. ContainerD.self is Type, not value of D.
let r16 = typeCheckShouldBeFailure(ContainerD.self)     // true. wrong. 

let r17 = ContainerE.self is ContainerE.Wrapped.Type    // true. ok.
let r18 = typeCheckShouldBeSuccess(ContainerE.self)     // false. wrong. It should be same of r17.
let r19 = ContainerE.self is ContainerE.Wrapped         // false. ok.
let r20 = typeCheckShouldBeFailure(ContainerE.self)     // true. wrong. It should be same of r19.
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

1 participant