tracker issue : CF-3749296

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

Built-in functions as "first class" glitch in function expressions

| View in Tracker

Status/Resolution/Reason: Closed/Won't Fix/

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 04/24/2014

Components: Language

Versions: 11.0

Failure Type:

Found In Build/Fixed In Build: PublicBeta /

Priority/Frequency: Minor / Some users will encounter

Locale/System: ALL / Platforms All

Vote Count: 1

See http://cfmlblog.adamcameron.me/2014/04/coldfusion-11-quick-look-at-what-data.html

{code}
writeOutput("<h3>Built-in function</h3>");
writeOutput("<h4>Via direct reference</h4>");
safe(function(){
    writeDump(var={object=mid, type=midref.getClass().getName()});
});

writeOutput("<h4>Via indirect reference</h4>");
safe(function(){
    var midRef = mid;
    writeDump(var={object=midref, type=midref.getClass().getName()});
});

function safe(f){
    try {
        f();
    }catch(any e){
        writeOutput("#e.type#: #e.message#; #e.detail#<br>");
    }
}
{code}

Errors with:

Via direct reference
Expression: Variable MID is undefined.; 

Via indirect reference
Expression: Variable MID is undefined.; 

Neither should error

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

Watson Bug ID:	3749296

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

The problem looks to be in calling any method on built in function writeDump(mid.getClass().getName()); // Errors out The following code works fine ------------ writeOutput("<h3>Built-in function</h3>"); writeOutput("<h4>Via direct reference</h4>"); safe(function(){ writeDump(var={object=mid}); }); writeOutput("<h4>Via indirect reference</h4>"); safe(function(){ var midRef = mid; writeDump(var={object=midref}); }); function safe(f){ try { f(); }catch(any e){ writeOutput("#e.type#: #e.message#; #e.detail#<br>"); } } ------------- Could you please confirm the same? If this is true, then we will close this bug and log another one.
Comment by Rupesh K.
12562 | May 02, 2014 09:06:19 PM GMT
Cheers for looking at this. Actually both the function expression and the writeDump() are red herrings. Better repro: writeOutput("direct method call<br>"); try { result = {}; result.object=mid; result.type = mid.getClass().getName(); writeOutput("OK<br>"); }catch(any e){ writeOutput("#e.type#: #e.message#; #e.detail#<br>"); } writeOutput("<hr>"); writeOutput("indirect method call<br>"); try { midRef = mid; result = {}; result.object=midRef; result.type = midRef.getClass().getName(); writeOutput("OK<br>"); }catch(any e){ writeOutput("#e.type#: #e.message#; #e.detail#<br>"); } writeOutput("<hr>"); The first one errors; the second is fine. -- Adam
Comment by External U.
12563 | May 03, 2014 03:23:48 AM GMT
The issue seems to be in calling method on the BIF reference. So this breaks. mid.getClass().getName(); however, the function can be passed around without any issue. I don't see many use cases of calling methods on the BIF reference and therefore it looks to be a very low priority bug. Am I missing something?
Comment by Rupesh K.
12564 | May 07, 2014 07:59:37 AM GMT
Yeah, am OK to downgrade it. I think I probably didn't pay attention to what I was doing when I raised the ticket (although your priority labels are a bit vague: "some" as opposed to "few"). I don't even care if you fix it or not, to be frank... I only came across it because I was doing research into how they worked for the blog. Ppl won't usually be doing that. It's a bit odd/interesting that one cannot call the method on the function itself, but if one makes a reference to it, then one can? -- Adam
Comment by External U.
12565 | May 07, 2014 08:04:18 AM GMT
Awdhesh will investigate that.
Comment by Rupesh K.
12566 | May 07, 2014 08:09:44 AM GMT
There is hardly any good usecase of calling a functionon a BIF (mid in here). I can't think any function other than getClass() being called on BIF. The effort does not look worthy fixing it.
Comment by Awdhesh K.
12567 | November 17, 2014 07:22:06 AM GMT
Awdhesh, that's just a repro case to demonstrate the point. Pls go read the blog article (especially the last code example). That's why I linked to it. For you to know to read it. It is a trivial thing, sure, but it looks to me to be representative of some sloppy coding somewhere which you might want to look at. That said, I will lose no sleep if you don't deal with it.
Comment by External U.
12568 | November 17, 2014 07:29:52 AM GMT
Built-in functions and user-defined functions should behave consistently in all places where a function can be passed or is expected as an argument.
Vote by External U.
12569 | November 26, 2015 07:12:38 AM GMT