I am developing my first project with Swift. Yesterday I attempted to add protocols ExpressibleByStringLiteral, ExpressibleByIntegerLiteral to a numerical class. I could get the changes to compile but could not get an object to instantiate with them and would get a fatal error when I ran the project. I could not even get the debugger to break in the two inits. Then I happen to discover the issue. If I instantiate an object of this class by any init method that are not one of these two protocols then the protocols will work fine from then on. In other words I can't use either of these two protocols first to instantiate an object of the class. Both protocol inits work perfectly when they are eventually called.
Is this a bug or am I missing something to enable the protocols? It looks like both of these protocols are depending on the fact that any instance of the class exists and has been instantiated.
Example:
This code segment works:
// all variables are APMInt
ll = APMInt(I64: 20) // instantiation that doesn't use protocol ExpressibleByStringLiteralor or ExpressibleByIntegerLiteral
ii = 3
jj = 4
print(ii * jj)
ii = "99"
jj = "88"
print (ii - jj)
kk = ii * jj
This code fails:
// all variables are APMInt
ii = 3
jj = 4
print(ii * jj)
ii = "99"
jj = "88"
print (ii - jj)
kk = ii * jj
Result:
Thread 1: EXC_BAD_ACCESS (code=2, address=0x7fff5965dea8) on line with print(ii * jj) because the objects ii and jj are garbage since they did not really go through their inits