Closed GoogleCodeExporter closed 8 years ago
Could be same as issue 270. Just noticed the similarity...
Original comment by roshanda...@gmail.com
on 25 Jul 2010 at 1:52
This issue seems to be partially fixed by # 270 fix, but looks like it can
still be improved.
-------------------------
def foo(String[] s){println s.length}
foo(['a']) // outputs 1
-------------------------
But the code below still fails saying "Cannot find constructor". Going by the
above behavior, it seems like it should transform it into a String array of
length 2.
-------------------------
def foo(String[] s){println s.length}
foo(['a', 'b'])
-------------------------
Looks a bit inconsistent - unless there is some explanation I am missing.
Original comment by roshanda...@gmail.com
on 26 Jul 2010 at 6:54
The issue still open. Fix is coming :)
Original comment by alex.tka...@gmail.com
on 26 Jul 2010 at 7:17
Roshan, please have a look on VarargsMethodTest from GroovyCore and let me know
what do you think. I am not sure what should right behavior be.
Original comment by alex.tka...@gmail.com
on 26 Jul 2010 at 9:48
If we have the following code
------------------------------
foo( ['a', 'b'] )
def foo(T[] args) {}
------------------------------
* option 1 could be - new T[] {new T('a', 'b')}
* option 2 could be - new T[] {new T('a'), new T('b')}
The issue was raised expecting option(2) to be the behavior, but going by core
groovy's VarargsMethodTest, option 1 seems a better choice to me (right?).
If option 1) is taken to be the correct one - the problem is that 1) works
fine, but 2) does not.
---------------------------
class Test {
def a, b
Test(String a, String b) {this.a = a; this.b = b}
}
def foo(Test[] s){ s }
Object[] ret
/* 1) - start */
ret = foo(['a1', 'b1'])
assert ret.class.array
assert ret.length == 1
assert ret[0].dump().contains('a=a1 b=b1')
/* 1) - end */
/* 2) - start */
ret = foo([ ['a1', 'b1'], ['a2', 'b2'] ])
assert ret.class.array
assert ret.length == 2
assert ret[0].dump().contains('a=a1 b=b1')
assert ret[1].dump().contains('a=a2 b=b2')
/* 2) - end */
-----------------------------
Original comment by roshanda...@gmail.com
on 26 Jul 2010 at 10:38
I think option 1 should be our choice. At the end of the day you dont need
foo([a,b])-syntax for var args because you can always use simply foo(a,b)
Original comment by alex.tka...@gmail.com
on 26 Jul 2010 at 10:48
Then may be there is nothing else to fix.
foo([ ['a', 'b'], ['c', 'd'] ]) should also become
1) new T[] {new T(['a','b'], ['c','d'])} - invoking T.<init>(List, List),
instead of
2) new T[] {new T('a', 'b'), new T('c', 'd')}?
If case 1) behavior is correct, it already works that way right now, and maybe
we can just add a few test cases to capture the behavior and be done with it.
Original comment by roshanda...@gmail.com
on 26 Jul 2010 at 10:54
Original comment by alex.tka...@gmail.com
on 26 Jul 2010 at 5:49
Original issue reported on code.google.com by
roshanda...@gmail.com
on 25 Jul 2010 at 1:48