Missing parameters are treated as zero!

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderator: Klaus

Post Reply
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Missing parameters are treated as zero!

Post by [-hh] » Sat Sep 26, 2015 7:15 pm

WARNING!

I needed a few hours to find out why a (lengthy) handler
gave me wrong results. I couldn't believe it.

If you have a handler with one or more parameters
then to call this handler WITHOUT parameters is, with LC,
NOT the same as a call with empty parameters:


---> LC treats *missing* params as zero !!!! <---

Make a new stack, 1 button, 1 field. Script the button:

Code: Select all

on mouseUp
   put empty into fld 1
   -- variant 1: Call the handler without parameter
   checkIt        --> yields true true
   -- variant 2: Call the handler with an empty parameter
   put empty into y
   checkIt y      --> yields true false
end mouseUp

on checkIt x
    put cr & (x is empty) && (x is "0") after fld 1
end checkit
I started to check this with LC 8.0.0-dp-5, then went back over LC 7, LC 6 down to LC 5.5.5. They all give the same result, on Mac/Linux/Win, please correct me if it is different with you.
HC on an emulated MacPlus yields for both variants "true false" what is logically correct, IMHO.

Is there a "List of Warnings" about such things?
Knowing the above "feature" had saved me a lot of time.
shiftLock happens

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1232
Joined: Thu Apr 11, 2013 11:27 am

Re: Missing parameters are treated as zero!

Post by LCMark » Mon Sep 28, 2015 8:05 am

This is one of those anomalies which we're stuck with at the moment - I'll file it as such in the Quality Centre in due course.

We know it's not a behavior that is easily changed, as 7 originally worked the way you expected and peoples code broke. If a parameter is unspecified its value is 'undefined' which is treated subtly differently for type coercion.

Post Reply