import CoreGraphics
let p = CGPoint(x: 1, y: 2)
print(p)
compiles and runs as expected without any compiler flags:
$ swiftc --version
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.2.0
$ swiftc test.swift && ./test
(1.0, 2.0)
But doing a release build, or as here compiling with -O, it will run in this unexpected way:
$ swiftc -O test.swift && ./test
warning: the Swift runtime was unable to demangle the type of field 'x'. the mangled type name is '12CoreGraphics7CGFloatV'. this field will show up as an empty tuple in Mirrors
warning: the Swift runtime was unable to demangle the type of field 'y'. the mangled type name is '12CoreGraphics7CGFloatV'. this field will show up as an empty tuple in Mirrors
CGPoint(x: (), y: ())
I'm surprised that I couldn't find anything when searching for this, or that I haven't noticed it earlier.
This is the default toolchain of Xcode 11.3.1 (11C504), which I've been using for some time. It doesn't seem to happen in larger programs (still command line programs, using CGPoint, compiled with -O).
Can anyone reproduce this or is it only me / my system?
Yeah, only on 11.3.1. I think it's probably fixed on 5.2, but I don't have access to Xcode 11.4 at the moment. Anyway, you can do p.debugDescription which should print (1.0, 2.0) for you.
tim@sequoia /tmp % sudo xcode-select -s /Applications/Xcode-beta.app
tim@sequoia /tmp % swiftc --version
Apple Swift version 5.2 (swiftlang-1103.0.25.1 clang-1103.2.32.5)
Target: x86_64-apple-darwin19.4.0
tim@sequoia /tmp % swiftc -O test.swift && ./test
(1.0, 2.0)
vs Xcode 11.3.1:
tim@sequoia /tmp % sudo xcode-select -s /Applications/Xcode.app
tim@sequoia /tmp % swiftc --version
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.4.0
tim@sequoia /tmp % swiftc -O test.swift && ./test
warning: the Swift runtime was unable to demangle the type of field 'x'. the mangled type name is '12CoreGraphics7CGFloatV'. this field will show up as an empty tuple in Mirrors
warning: the Swift runtime was unable to demangle the type of field 'y'. the mangled type name is '12CoreGraphics7CGFloatV'. this field will show up as an empty tuple in Mirrors
CGPoint(x: (), y: ())