From 7601fe65f97efbebfeb01a47df32bf33ec75f455 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Mon, 10 Jul 2023 13:59:22 +0200 Subject: [PATCH] fix diagnostic location for `@UDA auto f() {}` --- src/dscanner/analysis/auto_function.d | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/dscanner/analysis/auto_function.d b/src/dscanner/analysis/auto_function.d index 8bfce40d..40826264 100644 --- a/src/dscanner/analysis/auto_function.d +++ b/src/dscanner/analysis/auto_function.d @@ -47,14 +47,15 @@ public: package static const(Token)[] findAutoReturnType(const(FunctionDeclaration) decl) { - auto autoFunTokens = decl.storageClasses - .map!(a => a.token.type == tok!"auto" - ? [a.token] - : a.atAttribute - ? a.atAttribute.tokens - : null) - .filter!(a => a.length > 0); - return autoFunTokens.empty ? null : autoFunTokens.front; + const(Token)[] lastAtAttribute; + foreach (storageClass; decl.storageClasses) + { + if (storageClass.token.type == tok!"auto") + return storageClass.tokens; + else if (storageClass.atAttribute) + lastAtAttribute = storageClass.atAttribute.tokens; + } + return lastAtAttribute; } override void visit(const(FunctionDeclaration) decl) @@ -195,6 +196,9 @@ unittest ^^^^ [warn]: %s +/ auto doStuff(){} /+ ^^^^ [warn]: %s +/ + @Custom + auto doStuff(){} /+ + ^^^^ [warn]: %s +/ int doStuff(){auto doStuff(){}} /+ ^^^^ [warn]: %s +/ auto doStuff(){return 0;} @@ -203,6 +207,7 @@ unittest AutoFunctionChecker.MESSAGE, AutoFunctionChecker.MESSAGE, AutoFunctionChecker.MESSAGE, + AutoFunctionChecker.MESSAGE, ), sac); assertAnalyzerWarnings(q{ @@ -275,10 +280,14 @@ unittest auto doStuff(){} // fix @property doStuff(){} // fix @safe doStuff(){} // fix + @Custom + auto doStuff(){} // fix }c, q{ void doStuff(){} // fix @property void doStuff(){} // fix @safe void doStuff(){} // fix + @Custom + void doStuff(){} // fix }c, sac); stderr.writeln("Unittest for AutoFunctionChecker passed.");