tink_anon icon indicating copy to clipboard operation
tink_anon copied to clipboard

Merge fails to recognise condition in expr

Open serjek opened this issue 4 years ago • 1 comments

This does not work:

var a = {v: "none"};

function getResult(isYes:Bool)
	return tink.Anon.merge(a, isYes ? {v:"it works"} : {});

trace(getResult(true));
trace(getResult(false));

OTOH this works:

tink.Anon.merge(a, {v: isYes ? "it works" : ""});

I believe it is not trivial thing to fix (if even possible) so adding a compilation error and a notion to readme about this kinds of limitation would be useful.

serjek avatar Nov 20 '20 19:11 serjek

I think the readme has clearly stated that the function takes expressions and the supported expressions are already listed.

This falls into the third case and the reason of your problem can be revealed by a $type print:

$type(isYes ? {v:"it works"} : {}); // {}

i.e. no fields will get merged from this expression

kevinresol avatar Nov 22 '20 13:11 kevinresol