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-8516] NSNumber.init returns instance of NSConcreteValue #51036
Comments
@swift-ci create |
There are two "bugs" here: one is an ambiguous reference created by the code as written; specifically the call to
instead of the qualified
. The other side of it is the inference of the array literal type. If the array contains a Double it should all be interpreted as a Double.
|
The unrecognized selector is the map calling NSNumber() which is invalid and produces a nonsensical result. Not sure why map calls that... which seems like a really gnarly bug. |
Ugh, it's specifically picking |
Sadly NSNumber and NSValue have some complicated history in the regards to their initializers but that failure is pretty awful, @belkadan please feel free to re-assign that radar appropriately to a compiler bug. |
"it's specifically picking |
I'm not sure what changed from Swift 4.1, but that's important information, so thank you. Separating the array to a constant means deciding on a type for the array first, without looking at how it's going to be used. In that case, the only information the compiler has is that the elements are |
Hmm, I see. I think a figured out why it worked in previous versions of swift. Code
doesn't compile in swift 4.1 with error
and compiles successfully in 4.2 (of course it fails at runtime). So it seems like in swift 4.1 compiler doesn't have any choice other than correct initializer.
And it prints any in both swift 4.1 and 4.2. |
There is another interesting case with nil-coalescing operator _ = ("1" as String?).map { Float($0) ?? 0 }.map(NSNumber.init).map { $0.doubleValue } btw, this bug can be exceptionally hard to debug 🙂 Initial case that I reported almost two years ago was met in following circumstances: I had an animation with key times: let fullDuration: TimeInterval = ...
let firstStepDuration: TimeInterval = ...
let animation = CAKeyframeAnimation(keyPath: #keyPath(CALayer.transform))
animation.keyTimes = [0, firstStepDuration / fullDuration, 1].map(NSNumber.init) // <- it is array of NSValues, not NSNumbers, but we don't know it yet
....
layer.add(animation, forKey: nil) And of course, given forgiving nature of objc, that code doesn't crash, but it crashes when this animation is actually applying, in another runloop without any traces for above code. To debug this, I wrote down every memory address of created animations, had to inspect and debug assembly of core animation code to find out which animation had wrong values, and then I've found a match with above code. |
Environment
Xcode Version 10.0 beta 5 (10L221o)
Additional Detail from JIRA
md5: ddbc0a221a0bcf1304753842fa034776
is duplicated by:
Issue Description:
Encountered bug with unrecognised selector exception. After digging it down, it appeared that there was NSConcreteValue in swift array of NSNumbers.
Code to reproduce:
It throws:
Workarounds:
The text was updated successfully, but these errors were encountered: