[BUG]Syntax error

i think i found two bugs with this one:
this function throws a syntax error toast

exposed function locationLineClicked(xC:collection)->xC:collection
	var myForm: 4d.WebForm
	var event : object
	var row:integer
	var newValue:string


	myform=webForm
	event=webEvent

	row=event.data.row

	//<toggle selected>
		if (event.data.name=="selected")
			newValue=this._notSelected()
			if (xC[row].selected)==this._notSelected()
				newValue=this._selected()
			end//if (xC[row].selected)==this._notSelected()
			xC[row].selected=newValue
		end //if (event.data.name==this._selected())
	//</toggle selected>

if i change the return value -> xC : collection to
: collection (and, add return xC at the bottom), the problem goes away

so:

  1. i don’t think that declaration should be throwing a syntax error and
  2. even if i have the debugger on, the debugger never appears, despite the syntax error toast.

Hello Mikey,

When you use the same name for both the function parameter and the result variable, it becomes unclear which one you are referring to in certain contexts.

Consider this example:

exposed function locationLineClicked(xC : collection) -> xC : collection
	if (xC[row] == "something")

	end

	// Here, which 'xC' are you referring to?
	// Is it the function parameter or the result variable?

The parser may have difficulty distinguishing between the two occurrences of xC . When you change the name of the function parameter to varTestParam, the ambiguity is resolved:

exposed function locationLineClicked(varTestParam : collection) -> xC : collection	
	if (varTestParam[row]  == "something")

	end
	
    // Now, 'varTestParam' refers to the function parameter, and 'xC' to the result variable

Best regards,

this might not be the right place for this discussion, since this might more of a 4d question, i guess (but it’s weird that i have not encountered this issue, before now). anyway, here goes:
it’s weird that the parser would be confused by this syntax. it’s the same reference. that’s what we’re going for - pass the reference in, modify it, return it. i thought 4d was going for with orda, which is why a .copy() function was added, since variables in orda are references, not values.
whether i change the declaration to

exposed function locationLineClicked(xC : collection) : collection
   // modify xC
   return xC

or

exposed function locationLineClicked(pC : collection) -> rC : collection
  rC=pC

it’s the same reference. it’s just in the second case it’s gotten an extra identifier, first.

Hello Mikey,

You’re absolutely correct, object variables being references might suggest that using the same name is straightforward, especially in cases like this:

exposed function locationLineClicked(inputCollection: collection) -> inputCollection: collection
    row = /* some logic to determine the row index */

    if (inputCollection[row] == "something")
        inputCollection[inputCollection.length-1] = "modified something"
    end

However, the parser insists on different names to prevent potential conflicts even in these simple cases. This limitation becomes more evident in scenarios like the following:

exposed function locationLineClicked(inputCollection: collection) -> inputCollection: collection
    row = /* some logic to determine the row index */

    if (inputCollection[row] == "something")
        inputCollection[inputCollection.length-1] = "modified something"
    end

    // Check if last element of the Original collection equals to "end"
    if (inputCollection[inputCollection.length-1] == "end")
        // Due to the modifications above, this condition will not be satisfied
    end

In this scenario, changing the content of the original collection inputCollection within the initial condition leads to a change in its original state.

Consequently, if your logic involves re-evaluating the value of the last element of the original collection inputCollection, it prevents the final condition from being met. This is because, due to the modifications made earlier, the last element will never be equal to “end.”

Best regards,

1 Like

Hello Mikey!

It is not possible to declare the same variable twice as an input and output for your function, we will create a bug to throw an error for it.

1 Like

thanks for the explanation.

1 Like