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-2498] Foo.self is AnyObject incorrectly claims it always returns true #45103

Closed
lilyball mannequin opened this issue Aug 27, 2016 · 2 comments
Closed

[SR-2498] Foo.self is AnyObject incorrectly claims it always returns true #45103

lilyball mannequin opened this issue Aug 27, 2016 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Aug 27, 2016

Previous ID SR-2498
Radar None
Original Reporter @lilyball
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 3.0 (swiftlang-800.0.43.6 clang-800.0.38)
Target: x86_64-apple-macosx10.9

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

md5: 2451fc1637b9025dc20c2e0c5fb85bd0

duplicates:

  • SR-2420 AnyObject not working in Xcode8 beta6

Issue Description:

With Xcode 8 beta 6, if I write Foo.self is AnyObject, where Foo is a generic parameter or is something known to be a value type (e.g. a struct), the compiler warns me warning: 'is' test is always true, but at runtime it evaluates to false.

struct Foo {
    var x: Double
    var y: Double
}

print(Foo.self is AnyObject)

Compiler output:

unnamed.swift:6:16: warning: 'is' test is always true
print(Foo.self is AnyObject)
               ^

Runtime output:

false
@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Aug 27, 2016

FWIW I think the error here is the warning, not the runtime behavior. My use-case here is explicitly trying to check if a generic parameter is an object type. I don't want to invoke the new automatic value-type boxing behavior.

@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Aug 27, 2016

Hmm, after some quick experimentation, it looks like saying Foo.self is AnyObject.Type actually does what I want with no warning. So I guess I'm not sure how Foo.self is AnyObject should actually behave (but however it behaves, the compiler warning and runtime behavior need to be consistent).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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

0 participants