Fix === operator to check for type equality, changes to == behaviour

Description

foo = 'test' foo == 'test' foo === 'test'

This code run from a REPL outputs true, false because it checks to see if the two variables are the same objects in memory. The === has been widely accepted to perform a type check in languages like JavaScript however (which would return true in both cases).

Change the === operator to check for value equality and type equality instead. This will bring Lucee more in line with other languages and will be a much more useful operator in a dynamic language.

It's also worth noting, that this change will be loosening the current definition so no existing code will start returning false that currently returns true. I personally think anyone using it thought it was doing a type check all along (if anyone has, in fact, been using this).

Breaking Changes

this also affects the == operator with complex objects to match ACF, see https://luceeserver.atlassian.net/browse/LDEV-4548

Activity

Show:

Pothys - MitrahSoft 12 June 2023 at 07:56

I've checked this ticket with lucee version 6.0.0.451-SNAPSHOT. Now === operator are works fine and the issue is solved.

Zac Spitzer 14 October 2022 at 09:38
Edited

the main eeq functions (used in bytecode) are found here

https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/runtime/op/OpUtil.java#L796

https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/runtime/interpreter/ref/util/RefUtil.java#L44

<cfscript> a= 1; b =2; c = (b === a); </cfscript>

generates the following bytecode

paramPageContext.us().set(KeyConstants._A, ConstantsDouble._1); paramPageContext.us().set(KeyConstants._B, ConstantsDouble._2); paramPageContext.us().set(KeyConstants._C, Caster.toBoolean( Operator.eeq( paramPageContext.us().get(KeyConstants._B), paramPageContext.us().get(KeyConstants._A)) ) );

Zac Spitzer 2 May 2022 at 17:18

I’ve closed the linked ticket as it’s a duplicate

has just blogged about this https://blog.adamcameron.me/2022/05/cfml-with-lucee-true-isnt-necessarily.html

Fixed

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Fix versions

Priority

Created 20 April 2017 at 20:20
Updated 16 June 2023 at 15:36
Resolved 12 June 2023 at 07:57

Flag notifications