Bug 18102 – Filename accepted as UDA

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-12-18T21:16:21Z
Last change time
2017-12-20T19:50:06Z
Assigned to
No Owner
Creator
johanengelen

Comments

Comment #0 by johanengelen — 2017-12-18T21:16:21Z
Testcase: ``` // File: uda_bug.d @uda_bug void foo() {} ``` `dmd -c -o- uda_bug.d` should compile with an error but doesn't. Somehow the filename can be used as an UDA. I could not find this in the spec, it's an accepts-invalid bug?
Comment #1 by ketmar — 2017-12-18T22:10:45Z
module name, not file name. module name is a symbol (it has no type, yet it is still a symbol), hence it is allowed.
Comment #2 by schveiguy — 2017-12-19T15:05:04Z
ketmar is right, it's the module name (if you don't supply a module name it is implied from the filename). It doesn't make a lot of sense to use a module name as an attribute (I can't think of a good use case). Though I'm not sure if it's really that horrible of an allowance.
Comment #3 by johanengelen — 2017-12-20T19:29:08Z
Thanks for explanation, of course, doh! :-) The way I found out about this is that I did something similar to this: ``` // File weak.d import ldc.attributes; //contains `weak` type @weak void foo() {} ``` which then didn't apply `ldc.attributes.weak` to `foo`. The file name (--> module name) "hijacked" the `weak` identifier... I guess I should learn that the filename is part of the program. Anyway, mark as resolved?
Comment #4 by schveiguy — 2017-12-20T19:50:06Z
Yeah we can close. OT a bit, one glaring problem in D's module system is that top-level modules or packages interfere a great deal with normal symbols. We will have to deal with it at some point.