0

According to this question I tried in playground of Swift

extension Double {
  func __conversion() -> UInt8 { return UInt8(self) }
  func __conversion() -> Int { return Int(self) }
  // add more if you need to
}

var d = 1.0
var u8 : UInt8 = d

But that just produces a stack trace:

Playground execution failed: error: MyPlayground.playground:8:18: error: cannot convert value of type 'Double' to specified type 'UInt8' var u8 : UInt8 = d ^ UInt8( )

  • thread #1: tid = 0xa5e495, 0x000000010f86e360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground, queue = 'com.apple.main-thread`, stop reason = breakpoint 1.1
  • frame #0: 0x000000010f86e360 com.apple.dt.Xcode.PlaygroundStub-macosx'executePlayground

...

frame #51: 0x00007fffbce3a6b9 ViewBridge`-[NSXPCSharedListener resume] + 16

frame #52: 0x00007fffbce152c9 ViewBridge`NSViewServiceApplicationMain + 3022

frame #53: 0x000000010f86e3a2 com.apple.dt.Xcode.PlaygroundStub-macosx`main + 34

frame #54: 0x00007fffbecf8255 libdyld.dylib`start + 1

Is this a bug? Is support for __conversion silently terminated (I read something similar about Swift1)?

Community
  • 1
  • 1
qwerty_so
  • 35,448
  • 8
  • 62
  • 86

0 Answers0