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-13562] Type checking inconsistency with generic metatypes #56000

Open
swift-ci opened this issue Sep 18, 2020 · 3 comments
Open

[SR-13562] Type checking inconsistency with generic metatypes #56000

swift-ci opened this issue Sep 18, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13562
Radar rdar://problem/69153123
Original Reporter wangkun (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode Version 12.0 (12A7209) build in toolchain
Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
Target: x86_64-apple-darwin19.5.0

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

md5: 16f605757d589eb4f960b3df34c9414a

Issue Description:

There is an inconsistent behavior of the type checking primitives with generic metatypes.

When I use xcode 11.7 I don't have this problem, instead I have this problem with xcode 12

The code is available in the MyPlayground.playground.zip

protocol Protocol { }
enum Enum: Protocol { case `case` }
struct Struct: Protocol { }
class Class: Protocol { }

let enumInstance: Any = Enum.case
let structInstance: Any = Struct()
let classInstance: Any = Class()

print(enumInstance is Protocol) // true, as expected
print(structInstance is Protocol) // true, as expected
print(classInstance is Protocol) // true, as expected

func instanceCheck<TheType>(_ instance: Any, _: TheType.Type) -> Bool {
    return instance is TheType
}

print(instanceCheck(enumInstance, Protocol.self)) // true, as expected
print(instanceCheck(structInstance, Protocol.self)) // true, as expected
print(instanceCheck(classInstance, Protocol.self)) // true, as expected

let enumType: Any.Type = Enum.self
let structType: Any.Type = Struct.self
let classType: Any.Type = Class.self

print(enumType is Protocol.Type) // true, as expected
print(structType is Protocol.Type) // true, as expected
print(classType is Protocol.Type) // true, as expected

func typeCheck<TheType>(_ type: Any.Type, _: TheType.Type) -> Bool {
    return type is TheType.Type
}

print(typeCheck(enumType, Protocol.self)) // false, surprisingly
print(typeCheck(structType, Protocol.self)) // false, surprisingly
print(typeCheck(classType, Protocol.self)) // false, surprisingly

Some discusstion on forums

@typesanitizer
Copy link

@swift-ci create

@typesanitizer
Copy link

Just to clarify things here, are you saying the last 3 changed between Xcode 11.7 (returning true) and Xcode 12 (returning false)?

@swift-ci
Copy link
Collaborator Author

Comment by Kun Wang (JIRA)

Yes, In the last 3 check type Xcode 11.7 (returning true) and Xcode 12 (returning false)

@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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants