Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit c2b0348

Browse files
Fix passing of undefined variables of unbridgeable foreign types
The case of unbridgeable foreign types (like pointer) wasn't handled so optional forms of these types weren't usable as parameters as they'd fail due to the lack of bridging from undefined -> pointer.
1 parent a98e946 commit c2b0348

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

libscript/src/script-execute.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -534,18 +534,27 @@ MCScriptExecuteContext::ConvertToResolvedType(MCValueRef p_value,
534534
}
535535
else if (t_to_desc != nil)
536536
{
537-
// Export the foreign value
538-
if (!MCForeignValueExport(p_to_type.type,
539-
p_value,
540-
(MCForeignValueRef&)r_new_value))
541-
{
542-
Rethrow();
543-
return false;
544-
}
545-
}
546-
else
547-
{
548-
r_new_value = MCValueRetain(p_value);
537+
// If the foreign-typed slot is optional and the value is undefined,
538+
// don't try to export. This allows optional foreign slots to be set to
539+
// undefined when the type has no bridging type; without this, it is not
540+
// possible to set these slots to undefined!
541+
if (t_to_desc->doexport == nil &&
542+
p_to_type.is_optional &&
543+
p_value == kMCNull)
544+
{
545+
r_new_value = MCValueRetain(kMCNull);
546+
}
547+
else
548+
{
549+
// Export the foreign value
550+
if (!MCForeignValueExport(p_to_type.type,
551+
p_value,
552+
(MCForeignValueRef&)r_new_value))
553+
{
554+
Rethrow();
555+
return false;
556+
}
557+
}
549558
}
550559

551560
return true;

0 commit comments

Comments
 (0)