code_builder icon indicating copy to clipboard operation
code_builder copied to clipboard

Cannot call toString() on a list of non-literal expressions

Open m0nac0 opened this issue 4 years ago • 3 comments

Whenever I try to use literalList() and pass non-literal expressions, I get the error: Not a supported literal type

According to #225 this should be supported, though.

m0nac0 avatar Jul 22 '21 18:07 m0nac0

Please provide a minimal reproduction case. What code do you try to run which produces this error?

srawlins avatar Jul 22 '21 23:07 srawlins

When I tried to provide the minimal reproduction case, I noticed that the same code I couldn't get to work yesterday seems to work fine today. So it seems to have been some other issue on my side. Thank you nonetheless for responding!

m0nac0 avatar Jul 23 '21 06:07 m0nac0

I ran into this issue and I think the root cause is LiteralListExpression.toString()'s implementation:

https://github.com/dart-lang/code_builder/blob/743cb0a9f40079ff76fa45a6c2cb7d59a7ec4ad6/lib/src/specs/expression/literal.dart#L137

It passes each value to literal() which is what throws the reported error:

https://github.com/dart-lang/code_builder/blob/743cb0a9f40079ff76fa45a6c2cb7d59a7ec4ad6/lib/src/specs/expression/literal.dart#L35

I encountered this issue rather indirectly via the equalsDart matcher, because it invokes toString() in order to describe a mismatch.

I'm not very familiar with this code base, but I wonder if simply calling toString(), instead of literal(), on each value would be sufficient?

leonsenft avatar Nov 22 '21 23:11 leonsenft