Bug 16445 – string mixin allows shebang line in source

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-08-29T22:42:53Z
Last change time
2024-12-13T18:49:54Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Cauterite
Moved to GitHub: dmd#17773 →

Comments

Comment #0 by cauterite — 2016-08-29T22:42:53Z
This one is so hilarious I just had to submit it: ( https://dpaste.dzfl.pl/c10385f97af5 ) void main() { mixin(`#! asdf wxyz import std.stdio; writeln("LOL"); `); }; The only possible use for this feature I can think of is: mixin(import("something.d")); which is a pretty rare usage for mixins (I hope).
Comment #1 by b2.temp — 2016-08-30T00:24:02Z
Yes that's funny. I've tried to understand why this is accepted. If you compile this °°°°°a.d°°°°°° enum t = "#line 1\n#!a"; mixin(t); °°°°°°°°°°°°°° you get why this is accepted: mixin are normally located on line 1. When the shebang is explicitly mixed on a certain line that > 1, the normal error appears. So there is no bug. The shebang is removed as specified. You can also see that if you add a space before, an error is emitted.
Comment #2 by cauterite — 2016-08-30T10:10:12Z
(In reply to b2.temp from comment #1) > So there is no bug. The shebang is removed as specified. You can also see > that if you add a space before, an error is emitted. Well the bug is that shebang lines aren't applicable to string mixins, because they're not executed from a shell, so they should be a syntax error regardless. Especially if the mixin is an expression, where accepting a shebang line makes no sense whatsoever. The lexer has only one constructor, and it always strips "#!…\n" off unconditionally: https://github.com/dlang/dmd/blob/fb64019c2251d5f447967b9e796de8afc76e6226/src/lexer.d#L187
Comment #3 by robert.schadek — 2024-12-13T18:49:54Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17773 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB