Fix 23764 - Message printed twice: Usage of in on parameter

This commit is contained in:
Dennis Korpel 2023-03-08 14:37:10 +01:00 committed by Mathias LANG
parent 763b0a5fe5
commit a78115f36e
9 changed files with 38 additions and 4 deletions

View file

@ -777,6 +777,7 @@ extern (C++) final class Module : Package
else
{
scope p = new Parser!AST(this, buf, cast(bool) docfile, global.errorSink, &global.compileEnv);
p.transitionIn = global.params.vin;
p.nextToken();
p.parseModuleDeclaration();
md = p.md;

View file

@ -1937,6 +1937,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
scope p = new Parser!ASTCodegen(cd.loc, sc._module, str, false, global.errorSink, &global.compileEnv);
p.transitionIn = global.params.vin;
p.nextToken();
auto d = p.parseDeclDefs(0);

View file

@ -73,6 +73,14 @@ class ErrorSinkCompiler : ErrorSink
vdeprecationSupplemental(loc, format, ap);
va_end(ap);
}
void message(const ref Loc loc, const(char)* format, ...)
{
va_list ap;
va_start(ap, format);
vmessage(loc, format, ap);
va_end(ap);
}
}

View file

@ -27,6 +27,8 @@ abstract class ErrorSink
void warning(const ref Loc loc, const(char)* format, ...);
void message(const ref Loc loc, const(char)* format, ...);
void deprecation(const ref Loc loc, const(char)* format, ...);
void deprecationSupplemental(const ref Loc loc, const(char)* format, ...);
@ -47,6 +49,8 @@ class ErrorSinkNull : ErrorSink
void warning(const ref Loc loc, const(char)* format, ...) { }
void message(const ref Loc loc, const(char)* format, ...) { }
void deprecation(const ref Loc loc, const(char)* format, ...) { }
void deprecationSupplemental(const ref Loc loc, const(char)* format, ...) { }
@ -117,5 +121,21 @@ class ErrorSinkStderr : ErrorSink
va_end(ap);
}
void message(const ref Loc loc, const(char)* format, ...)
{
const p = loc.toChars();
if (*p)
{
fprintf(stderr, "%s: ", p);
//mem.xfree(cast(void*)p); // loc should provide the free()
}
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
fputc('\n', stderr);
va_end(ap);
}
void deprecationSupplemental(const ref Loc loc, const(char)* format, ...) { }
}

View file

@ -6107,6 +6107,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
const len = buf.length;
const str = buf.extractChars()[0 .. len];
scope p = new Parser!ASTCodegen(exp.loc, sc._module, str, false, global.errorSink, &global.compileEnv);
p.transitionIn = global.params.vin;
p.nextToken();
//printf("p.loc.linnum = %d\n", p.loc.linnum);

View file

@ -49,6 +49,8 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
Loc lookingForElse; // location of lonely if looking for an else
}
bool transitionIn = false; /// `-transition=in` is active, `in` parameters are listed
/*********************
* Use this constructor for string mixins.
* Input:
@ -2857,6 +2859,8 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
// Don't call nextToken again.
}
case TOK.in_:
if (transitionIn)
eSink.message(scanloc, "Usage of 'in' on parameter");
stc = STC.in_;
goto L2;

View file

@ -4756,6 +4756,7 @@ private Statements* flatten(Statement statement, Scope* sc)
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
scope p = new Parser!ASTCodegen(cs.loc, sc._module, str, false, global.errorSink, &global.compileEnv);
p.transitionIn = global.params.vin;
p.nextToken();
auto a = new Statements();

View file

@ -1119,9 +1119,6 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc)
fparam.type = fparam.type.addStorageClass(fparam.storageClass);
if (global.params.vin && fparam.storageClass & STC.in_)
message(loc, "Usage of 'in' on parameter");
if (fparam.storageClass & (STC.auto_ | STC.alias_ | STC.static_))
{
if (!fparam.type)
@ -4934,6 +4931,7 @@ RootObject compileTypeMixin(TypeMixin tm, Loc loc, Scope* sc)
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
scope p = new Parser!ASTCodegen(loc, sc._module, str, false, global.errorSink, &global.compileEnv);
p.transitionIn = global.params.vin;
p.nextToken();
//printf("p.loc.linnum = %d\n", p.loc.linnum);

View file

@ -5,7 +5,7 @@ TEST_OUTPUT:
---
compilable/transition_in.d(3): Usage of 'in' on parameter
compilable/transition_in.d(3): Usage of 'in' on parameter
compilable/transition_in.d(13): Usage of 'in' on parameter
compilable/transition_in.d(8): Usage of 'in' on parameter
compilable/transition_in.d(13): Usage of 'in' on parameter
---
*/