tracker issue : CF-4202194

select a category, or use search below
(searches all categories and all time range)

2018 Beta: `var` in `final var myvar` is unnecessary

| View in Tracker

Status/Resolution/Reason: Needs Review//NeedMoreInfo

Reporter/Name(from Bugbase): John Whish / ()

Created: 04/28/2018

Components: Language

Versions: 2018

Failure Type: Enhancement Request

Found In Build/Fixed In Build: 2018,0,0,308164 /

Priority/Frequency: Normal / All users will encounter

Locale/System: / Platforms All

Vote Count: 3

Problem Description:

If you use `final` for a variable in a function, to function scope it you need to do `final var myvar` to stop it bleeding. The extra `var` seems unnecessary to me. I'd like it if the foo example below worked as the bar one does.

function foo(){
  final a = "One"
  return a
function bar(){
  final var b = "Two"
  return b

x = foo()
y = bar()

writeOutput("IsNull(a): #isNull(a)#<br>") // NO
writeOutput("IsNull(b): #isNull(b)#<br>") // YES



Steps to Reproduce:

Run this:

Actual Result:

Without `var` the variable bleeds.

Expected Result:

`final` should imply `var` so that the variable does not bleed.

Any Workarounds:

Use `final var`.



-1. This ticket cannot be implemented b/c it would block ability to create a variables-scoped final variable from within a UDF after CF-4202341 is fixed.
Vote by Aaron N.
27392 | April 28, 2018 08:25:44 PM GMT
Related thread:
Comment by Aaron N.
27391 | April 28, 2018 08:27:14 PM GMT
+1 the term var contradicts final in my opinion. We certainly shouldn't have to use it conjunction to prevent bleeding.
Vote by Jamie P.
27637 | May 02, 2018 08:57:34 AM GMT
Hi all, Just to be clear, `final myVar = foo` should create `foo` in the default scope. Currently, that is always the `variables` scope. Inside UDFs, the bleeding issue should be fixed via a mechanism to assign all unscoped variables (such as `final myVar`) to the function-scope instead of the variables scope. A keyword, like var or final, shouldn't simultaneously affect both immutability -and- scope. They each serve their separate purpose. Thanks!, -Aaron
Comment by Aaron N.
27676 | May 05, 2018 01:28:53 AM GMT
Hi Adobe, This ticket cannot be 'fixed' due to CF-4202341. Since: 1) `function f(){foo="bar"}` must create variable named "foo" into variables scope 2) `function f(){var"bar"}` must create struct named "variables" into local scope (Lucee gets this right; filed as CF-4202341) Then: `function f(){final foo="bar"}` must create final variable named "foo" into variables scope Otherwise: There would be no way to create a variables-scoped final variable from within a UDF, b/c `function f(){final"bar"}` must create struct named "variables" into local scope Thanks!, -Aaron
Comment by Aaron N.
27723 | May 09, 2018 04:55:05 AM GMT