Bug 3073 – (D1 only) expressions starting with string mixin don't parse

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Windows
Creation time
2009-06-16T21:00:12Z
Last change time
2019-09-27T08:31:59Z
Keywords
patch
Assigned to
No Owner
Creator
BCS

Attachments

IDFilenameSummaryContent-TypeSize
687patch.difflookahead to see if semicolon followstext/plain601

Comments

Comment #0 by shro8822 — 2009-06-16T21:00:12Z
void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' this should work: http://www.digitalmars.com/d/1.0/expression.html#MixinExpression quoting Ary from the NG thread: ============================= Yes, at that point the parser is parsing statements, so if it finds a "mixin(...)" it turns it into a statement. I'm thinking about how to fix this. I think the parser should peek the next token after the closing parenthesis. If it's a semicolon, then treat it as a statement-mixin. Else, just invoke parseAssignExp and create a new ExpStatement. I modified this in Descent and it seems to work. :-) Here's the code (in Java, but the idea is simple to translate to C++): // inside Parser::parseStatement case TOKmixin: { Dsymbol d; t = peek(token); if (t.value == TOKlparen) { if (peekPastParen(t).value != TOKsemicolon) { Expression e = parseAssignExp(); s = new ExpStatement(loc(), e); } else { // mixin(string) nextToken(); check(TOKlparen); Expression e = parseAssignExp(); check(TOKrparen); check(TOKsemicolon); s = newCompileStatement(loc(), e); } break; } else { d = parseMixin(); s = newDeclarationStatement(loc(), d); break; } }
Comment #1 by ellery-newcomer — 2010-06-28T21:53:24Z
Created attachment 687 lookahead to see if semicolon follows
Comment #2 by razvan.nitu1305 — 2019-09-27T08:31:59Z
The issue does not appear in D2 and D1 is obsolete. Closing as WONTFIX.