I've run into a strange issue (which might be a Swift compiler bug) where I can't initialise a Double
from an Int
like so, Double(myInt)
, without the compiler throwing an error when the initialisation is performed in certain positions within my code. Here's a working example and a non-working example:
// Working example:
let width = Double(width)
textureDescriptor.mipmapLevelCount = 1 + Int(log2(width).rounded(.down))
// Non-working example
textureDescriptor.mipmapLevelCount = 1 + Int(log2(Double(width)).rounded(.down))
Here's the error that the second one gets:
error: ambiguous use of 'init(_:)'
textureDescriptor.mipmapLevelCount = 1 + Int(log2(Double(width)).rounded(.down))
^
Swift.Double:2:12: note: found this candidate
public init(_ v: Int)
^
Swift.Double:3:23: note: found this candidate
@inlinable public init<Source>(_ value: Source) where Source : BinaryInteger
^
Swift.BinaryFloatingPoint:3:23: note: found this candidate
@inlinable public init<Source>(_ value: Source) where Source : BinaryInteger
^
Strangely all 3 implementations seem to be within the standard library so it's not something that I introduced with my code (unless it's a Swift bug as far as I can see).
I haven't changed anything in that file for quite a while so somehow some other code changes have affected the resolution of the initialiser in that one particular spot.
Sadly I don't have the time at the moment to create a minimum reproducing case so I'm more just posting this in case it's useful to anyone working on a related issue.