Re: Varargs

Attila Szegedi <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Ah… okay, I totally forgot about that. Alright, that means that what you suggested as the fix should be sufficient.

On Aug 8, 2011, at 6:35 PM, Daniel Dekany wrote:

> Just so it's absolutely clear: The vararg support was already
> backported from 3.0 to 2.3.12, almost 4 years ago. But this
> backporting was wrong (and obviously it wasn't even tried if it
> works). So this should be fixed in 2.3 too, not just in 2.4.
> 
> -- 
> Best regards,
> Daniel Dekany
> 
> 
> Monday, August 8, 2011, 5:50:51 PM, Attila Szegedi wrote:
> 
>> Yeah, I think that would be sufficient. I did implement full vararg
>> support for 3.0, so whatever code is there should work. 
>> 
>> There's some additional work to be done at invocation time; i.e. if
>> the last argument is already an array of the requested type, you
>> should just pass it, otherwise you should construct an array. Also,
>> if one less argument is passed, you need to pass in a zero-length array.
>> 
>> Finally, there's a whole subset of issues with overloaded method
>> resolution in presence of varargs. Again, I did write all the code
>> for 3.0, and it should be straightforward to port it back to 2.4, we
>> just need someone to roll the sleeves up and do it. That's not me at the moment, unfortunately.
>> 
>> If Brian forks the project on GitHub, that's most welcome. We'll be happy to pull in changes.
>> 
>> Attila.
>> 
>> On Aug 4, 2011, at 11:46 AM, Daniel Dekany wrote:
>> 
>>> OK, I have looked into this, and it seems that this feature (varargs)
>>> has never worked in 2.3. FM 2.3.12 has just made things worse, as not
>>> even explicitly passing an array (like hasRoles(['foo', 'bar'])) works
>>> starting from there, while before 2.3.12 it certainly did. How nobody
>>> ran into this and reported for 4.5 years is beyond be. Also, varags
>>> has no test coverage in 2.3/2.4...
>>> 
>>> And now I will mostly talk to Attila (the author of BeansWrapper). The
>>> problem is this: BeansWrapper.populateClassMapWithBeanInfo(Class) in
>>> FM 3.0 calls componentizeLastArg(publicMethod.getParameterTypes(),
>>> publicMethod.isVarArgs())) to calculate SimpleMemberModel.argTypes,
>>> while 2.3/2.4 just calls publicMethod.getParameterTypes(). The
>>> componentizeLastArg method changes the vararg's type from array<T> to
>>> T. Thus in 2.3/2.4 the type of the vararg argument, according to
>>> SimpleMemberModel.argTypes[theIndexOfTheVarArg], will be array<T>,
>>> while in 3.0 it will be T. But all the other parts of the algorithm is
>>> the same as in 3.0, so the method call will fail both with
>>> hasRoles(["foo", "bar"]) and hasRoles("foo", "bar").
>>> 
>>> Would adding componentizeLastArg to 2.3/2.4 and calling it at the same
>>> two places as in 3.0 be a sufficient fix? Would it be backward
>>> compatible? I guess it would be, but you are still the one who knows
>>> this stuff inside out...
>>> 
>>> -- 
>>> Best regards,
>>> Daniel Dekany
>>> 
>>> 
>>> Wednesday, August 3, 2011, 6:19:59 PM, Brian Pontarelli wrote:
>>> 
>>>> On Aug 3, 2011, at 2:07 AM, Daniel Dekany wrote:
>>>> 
>>>>> Tuesday, August 2, 2011, 9:20:43 PM, Brian Pontarelli wrote:
>>>>> 
>>>>>> I've read that vararg method calls were added to 2.4.12 but I can't
>>>>>> find any good docs on how to use them and if there are any special
>>>>>> requirements. I have a varargs method that I'm trying to invoke from
>>>>>> a template and I'm getting an argument type mismatch exception:
>>>>>> 
>>>>>> public boolean hasRoles(String... roles) {
>>>>>>  ...
>>>>>> }
>>>>>> 
>>>>>> 
>>>>>> [#if user.hasRoles(["foo", "bar"])]
>>>>>>  …
>>>>>> [/#if]
>>>>>> 
>>>>>> Anyone know how to fix this?
>>>>> 
>>>>> AFAR it's supposed to Just Work (assuming you are using some
>>>>> BeansWrapper subclass as the object_wrapper setting, and it's 99% that
>>>>> you do). Have you tried user.hasRoles("foo", "bar"), without the []?
>>>> 
>>>> Yeah, tried that. It then complains about trying to convert String
>>>> to String[]. I do have a BeansWrapper sub-class, but all it does is set these two options:
>>>> 
>>>>       setExposeFields(true);
>>>>       setSimpleMapWrapper(true);
>>>> 
>>>> Not sure how to fix it, but I changed the method to take an
>>>> Iterable<String> and it is working.
>>>> 
>>>> -bp
>>>> 
>>>> 
>>>> ------------------------------------------------------------------------------
>>>> BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
>>>> The must-attend event for mobile developers. Connect with experts. 
>>>> Get tools for creating Super Apps. See the latest technologies.
>>>> Sessions, hands-on labs, demos & much more. Register early & save!
>>>> http://p.sf.net/sfu/rim-blackberry-1
>>>> _______________________________________________
>>>> FreeMarker-user mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>> 
>>> 
>> 
>> 
>> ------------------------------------------------------------------------------
>> BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
>> The must-attend event for mobile developers. Connect with experts. 
>> Get tools for creating Super Apps. See the latest technologies.
>> Sessions, hands-on labs, demos & much more. Register early & save!
>> http://p.sf.net/sfu/rim-blackberry-1
>> _______________________________________________
>> FreeMarker-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>> 
> 


------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts. 
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.