qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
177 stars 25 forks source link

Add mechanism to mark unused variables as ok #64

Closed j4m3z0r closed 6 years ago

j4m3z0r commented 6 years ago

Consider the following:

replace(BufferAndNativeTypes => (
    (Int, int),
    (Float, float),
    (Short, short),
    (UShort, ushort),
    (Byte, byte)));

            unroll((BufferType, NativeType) in BufferAndNativeTypes) {
                if(typeof(T) == typeof(NativeType)) {
                    return;
                }
            }

It will generate a warning, because NativeType isn't used.

Generally when I iterate over BufferAndNativeTypes I use both entries in the tuple, but here I don't. I generally like to eliminate all warnings where possible, so that it's meaningful when I do get one. I'd love to have a way to mark to LeMP that NativeType being unused is expected, so it doesn't need to generate a warning.

At present I'm doing this:

                #rawText("// "); #rawText(stringify(BufferType));

which works, but it's a bit of a hack.

qwertie commented 6 years ago

If you use (_, NativeType) the warning will go away. (If that didn't work I was going to suggest adding [#trivia_unused(BufferType)] before if, which would suppress it without producing output, as any unrecognized trivia will be ignored by the printer; this latter fix would not have been ideal since the definition of trivia will change).