Lambda parsing error in ternary expression

This is for @Zackster - ran into a parsing issue this morning, seems that Lucee can’t parse Lambda inside a ternary expression. Example:

var operation = true
    ? () => "foo",
    : () => "bar"
;

Lucee 6.x gives me some error about lambda/function expression not existing, or something like that (don’t have the code in front of me). I tried a few different syntax variations, but couldn’t get it to parse.

Just sharing cause I know you love some bugs!

1 Like

Without arrow functions it works.

Ah, nice! So it must just be a parsing issue.

1 Like

good find, please file a bug!

1 Like

Will do :+1:

This works correctly in Lucee without any parsing errors and confirms that lambdas can be used directly within ternary expressions.

1 Like

good catch @cfmitrah, the trailing comma after "foo", is wrong!

And perplexity agrees, LLMs are quite good at spotting these typos

https://www.perplexity.ai/search/why-does-this-error-var-operat-SUiwoxmpRo2BKt6SbYtkrw

2 Likes

Hmmm, that was probably just a typo in my example. That error is about ternary operator failure - I was seeing something more lambda-related. Let me see if I can reproduce the exact issue.

Ok, getting closer to narrowing down. I’m back to this error:

Type lucee/runtime/type/Lambda not present

lucee.runtime.type.Lambda not found by org.objectweb.asm [31]

Gonna see if I can isolate it.

@Zackster @cfmitrah ok, this can reproduce:

<cfscript>

	x = isCustomFunction( temp )
		? () => invoke( variables, "temp" )
		: temp
	;

	function temp() {}

</cfscript>

I just tried this on trycf.com.

  • Lucee 5 - works
  • Lucee 6 - breaks.
  • Lucee 7 - breaks.

At least I’m not crazy - will open a ticket later today.

Even more concise:

<cfscript>

	x = false
		? () => "a"
		: "b"
	;

</cfscript>

It seems that when using a ternary, BOTH options have to be lambda. If only one is lambda, it seems to break.

1 Like

are you getting this error? that’s an interesting error writing out the bytecode

lucee.runtime.exp.NativeException: Type lucee/runtime/type/Lambda not present
 at org.objectweb.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1062)
 at org.objectweb.asm.SymbolTable.addMergedType(SymbolTable.java:1286)
 at org.objectweb.asm.Frame.merge(Frame.java:1311)
 at org.objectweb.asm.Frame.merge(Frame.java:1244)
 at org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1612)
 at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1548)
 at org.objectweb.asm.commons.GeneratorAdapter.endMethod(GeneratorAdapter.java:1350)
 at lucee.transformer.bytecode.Page.writeOutCall(Page.java:1578)

Yes, exactly correct.

Yes, the same issue occurred: “Type lucee/runtime/type/Lambda not present” in ternary expressions.

Sorry my original example wasn’t reproducing it - I didn’t understand what the core issue was.

Bug posted: Jira

cheers, I added more of the stacktrace and the caused by section, that’s always important to include

Team work makes the dream work!

2 Likes