From 65e822ac412db0a89bf2e15bf9328a0dbd356dd9 Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Mon, 23 Dec 2024 11:36:05 -0500 Subject: [PATCH] fix: Fix generation of optional casts in binding_generator. --- tools/binding_generator/lib/src/common_helpers.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/binding_generator/lib/src/common_helpers.dart b/tools/binding_generator/lib/src/common_helpers.dart index e89fb6f..78dffb3 100644 --- a/tools/binding_generator/lib/src/common_helpers.dart +++ b/tools/binding_generator/lib/src/common_helpers.dart @@ -82,15 +82,15 @@ void writeReturnRead(ArgumentProxy returnType, CodeSink o) { o.p('return retPtr.value;'); break; case TypeCategory.engineClass: + final question = returnType.isOptional ? '?' : ''; if (returnType.isRefCounted) { - final question = returnType.isOptional ? '?' : ''; o.p('final realObj = gde.ffiBindings.gde_ref_get_object(retPtr.cast());'); o.p('final retVal = gde.dartBindings.gdObjectToDartObject(realObj.cast()) as ${returnType.rawDartType}$question;'); // Need to unreference the Ref as its destructor is never called o.p('retVal$question.unreference();'); o.p('return retVal;'); } else { - o.p('return gde.dartBindings.gdObjectToDartObject(retPtr.value) as ${returnType.rawDartType};'); + o.p('return gde.dartBindings.gdObjectToDartObject(retPtr.value) as ${returnType.rawDartType}$question;'); } break; case TypeCategory.builtinClass: