Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -6649,7 +6649,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
if (condition && ifbody)
s = new AST.IfStatement(loc, param, condition, ifbody, elsebody, token.loc);
else
s = null; // don't propagate parsing errors
s = new AST.ErrorStatement; // don't propagate parsing errors as null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems to me that these assignments are redundant with the fixed null checking in statementsem.d

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also please use ErrorStatement.get() (requires a rebase)

break;
}

Expand Down Expand Up @@ -6695,6 +6695,9 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
if (auto ds = parseDebugSpecification())
eSink.error(ds.loc, "%s `%s` declaration must be at module level", ds.kind, ds.toPrettyChars);

// Not valid as a statement; return ErrorStatement instead of null so
// callers (string mixin semantic) do not null-deref.
s = new AST.ErrorStatement;
break;
}
cond = parseDebugCondition();
Expand All @@ -6707,6 +6710,9 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
if (auto vs = parseVersionSpecification())
eSink.error(vs.loc, "%s `%s` declaration must be at module level", vs.kind, vs.toPrettyChars);

// Not valid as a statement; return ErrorStatement instead of null so
// callers (string mixin semantic) do not null-deref.
s = new AST.ErrorStatement;
break;
}
cond = parseVersionCondition();
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dmd/statementsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -5082,7 +5082,9 @@ private Statements* flatten(Statement statement, Scope* sc)
Statement s = p.parseStatement(ParseStatementFlags.curlyScope);
if (!s || global.errors != errors)
{
errorSupplemental(s.loc, "while parsing string mixin statement");
// Prefer a real source location; ErrorStatement uses Loc.initial.
const loc = (s !is null && s.loc.isValid()) ? s.loc : cs.loc;
errorSupplemental(loc, "while parsing string mixin statement");
return errorStatements();
}
a.push(s);
Expand Down
21 changes: 21 additions & 0 deletions compiler/test/fail_compilation/mixin_version_debug_assign.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
TEST_OUTPUT:
---
fail_compilation/mixin_version_debug_assign.d-mixin-15(15): Error: version `foo` declaration must be at module level
fail_compilation/mixin_version_debug_assign.d(15): while parsing string mixin statement
fail_compilation/mixin_version_debug_assign.d-mixin-20(20): Error: identifier expected, not `1`
fail_compilation/mixin_version_debug_assign.d(20): while parsing string mixin statement
---
*/

void main()
{
// Previously crashed dmd with ACCESS_VIOLATION: parseStatement returned null,
// then string-mixin semantic did errorSupplemental(s.loc, ...).
mixin("version = foo;");
}

void other()
{
mixin("debug = 1;");
}
Loading