CFLint icon indicating copy to clipboard operation
CFLint copied to clipboard

AVOID_USING_STRUCTNEW false positive with struct ordered

Open davidsf opened this issue 6 years ago • 4 comments

When declaring a ordered struct, I do:

a  = structNew( "ordered" );

and cflint complains about the use of structnew. I don't see in the docs another way to declare it.

davidsf avatar Dec 10 '18 10:12 davidsf

Good question. Here is the short form: a = {};

On Mon, Dec 10, 2018 at 5:55 AM David Sedeño [email protected] wrote:

When declaring a ordered struct, I do:

a = structNew( "ordered" );

and cflint complains about the use of structnew. I don't see in the docs another way to declare it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cflint/CFLint/issues/607, or mute the thread https://github.com/notifications/unsubscribe-auth/AFtZuwXalfW5gJ9IaVELRN-JDjjAsLRsks5u3j2WgaJpZM4ZLHlT .

ryaneberly avatar Dec 10 '18 22:12 ryaneberly

@ryaneberly That does not initialize it as an ordered struct. There is a literal syntax for ordered structs (see #534), but that cannot be used for initializing an empty ordered struct.

KamasamaK avatar Dec 10 '18 22:12 KamasamaK

Good point. Maybe that rule in lint should not fire if StructNew is used with parameters!

On Mon, Dec 10, 2018 at 5:30 PM KamasamaK [email protected] wrote:

@ryaneberly https://github.com/ryaneberly That does not initialize it as an ordered struct. There is a literal syntax for ordered structs (see #534 https://github.com/cflint/CFLint/issues/534), but that cannot be used for initializing an empty ordered struct.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cflint/CFLint/issues/607#issuecomment-445999274, or mute the thread https://github.com/notifications/unsubscribe-auth/AFtZuwvu_D3nMpe6cpeDuVH2jLPgAdA1ks5u3uCUgaJpZM4ZLHlT .

ryaneberly avatar Dec 11 '18 19:12 ryaneberly

So I'm not sure how I missed this, but I just found that there actually is a way to declare an empty ordered struct using the literal syntax. It is: var orderedStruct = [:] or var orderedStruct = [=]

However, it produces a parse error due to #534.

KamasamaK avatar Feb 20 '19 15:02 KamasamaK