Skip to content

Commit

Permalink
fix diagnostic location for @UDA auto f() {}
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Jul 10, 2023
1 parent c1e051b commit 7601fe6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/dscanner/analysis/auto_function.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;}
Expand All @@ -203,6 +207,7 @@ unittest
AutoFunctionChecker.MESSAGE,
AutoFunctionChecker.MESSAGE,
AutoFunctionChecker.MESSAGE,
AutoFunctionChecker.MESSAGE,
), sac);

assertAnalyzerWarnings(q{
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit 7601fe6

Please sign in to comment.