Here's the class (vast simplification of the original code, just to show the error):
class Foo { Str[] bar(Str line) { res := [,] line.split().each |v| { res.add(v) } return res } }
Here's the test:
class FooTest : Test { Void testBar() { f := Foo() verifyEq(["a", "b", "c"], f.bar("a b c")) } }
Here's the error:
sys::TestErr: Test failed: sys::Str[a, b, c] != sys::Obj?[a, b, c]
It gets the same error if the declaration of res is
res
Str[] res := [,]
Thanks!
It's because type of [,] is Obj?[,]. Type of expression is not inferred by the type of variable it's assigned to.
[,]
Obj?[,]
changes type of variable, not a list it references. Exception is made for field initialization only.
res := Str[,]
will fork though. But not for fields because they must have explicit type. See #986 for further clarification.
EDT: #986 doesn't clarify much. #269 does better.
Excellent, thanks!
Login or Signup to reply.
yachris Sat 18 Sep 2010
Here's the class (vast simplification of the original code, just to show the error):
Here's the test:
Here's the error:
It gets the same error if the declaration of
res
isThanks!
vkuzkokov Sat 18 Sep 2010
It's because type of
[,]
isObj?[,]
. Type of expression is not inferred by the type of variable it's assigned to.changes type of variable, not a list it references. Exception is made for field initialization only.
will fork though. But not for fields because they must have explicit type. See #986 for further clarification.
EDT: #986 doesn't clarify much. #269 does better.
yachris Sat 18 Sep 2010
Excellent, thanks!