From bb46b664b2fac9446eb8a9285a7aeb72465a73aa Mon Sep 17 00:00:00 2001 From: dafuga Date: Mon, 4 Mar 2024 12:37:04 -0800 Subject: [PATCH] fix: fixing cast error --- Sources/EOSIO/ABIDecoder.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/EOSIO/ABIDecoder.swift b/Sources/EOSIO/ABIDecoder.swift index 8d894d9..9a810f6 100644 --- a/Sources/EOSIO/ABIDecoder.swift +++ b/Sources/EOSIO/ABIDecoder.swift @@ -109,7 +109,13 @@ public extension ABIDecoder { case is UInt.Type: return UInt(try self.readVaruint()) as! T case let abiType as ABIDecodable.Type: - return try abiType.init(fromAbi: self) as! T + let decodedAbiType = try abiType.init(fromAbi: self) + // Instead of forcefully casting, verify the type at runtime. + if let result = decodedAbiType as? T { + return result + } else { + throw Error.typeNotConformingToABIDecodable(type) + } default: throw Error.typeNotConformingToABIDecodable(type) }