tracker issue : CF-3648120

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

Another example of scoping issues with inconsistent bahviour

| View in Tracker

Status/Resolution/Reason: Closed/Deferred/NotEnoughTime

Reporter/Name(from Bugbase): Andrew Scott / Andrew Scott (Andrew Scott)

Created: 10/09/2013

Components: Core Runtime

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final /

Priority/Frequency: Major / Most users will encounter

Locale/System: English / Win 2008 Server

Vote Count: 8

Problem Description:

While doing a bit of code re-factoring I ran into an error with the following code.

public void function myMethod(testVar) {
	var testVar = "defined locally!!";
}

The error indicated that the testVar already existed in the arguments scope, this is wrong behavior to begin with. But if we use the new local scope like such

	public void function myMethod(testVar) {
		local.testVar = "defined locally!!";
	}

We actually get the correct behavior, where the testVar variable is stored locally. Where as the first example, is incorrectly throwing an error.


Steps to Reproduce:

Actual Result:

Expected Result:

Any Workarounds:

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3648120

External Customer Info:
External Company:  
External Customer Name: ascott67
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

Yeah, the restriction on VAR statements should be lifted. It used to make sense up until CF9 when the general approach to VARing was loosened in that one can VAR variables anywhere in a function, and can re-VAR them too, without error.
Vote by External U.
14297 | December 10, 2014 07:49:46 AM GMT
Pls reopen & fix.
Comment by External U.
14296 | December 10, 2014 07:49:55 AM GMT
+1 ///////////////////////////////
Vote by External U.
14298 | December 11, 2014 01:02:58 AM GMT
can we get consistent use of scopes especially now closures seem to have yet another set of scope "quirks" to deal with.
Vote by External U.
14299 | July 13, 2015 06:24:24 AM GMT
+1 The behaviour should be consistent
Vote by External U.
14300 | July 13, 2015 06:25:58 AM GMT
It's silly that the compiler fails over this: it should work.
Vote by External U.
14301 | August 05, 2015 03:09:48 AM GMT
Been bitten by this more than once, learned to work around it, but I don't think I should.
Vote by External U.
14302 | August 05, 2015 03:26:38 AM GMT
+1 . As var and local scope refers to same scope, so in both the places it should behave same.
Vote by External U.
14303 | August 05, 2015 04:16:43 AM GMT
+1 inconsistent behaviour on logic that should return identical outcomes needs to be consolidated
Vote by External U.
14304 | August 05, 2015 04:56:37 AM GMT