Bug 17404 – creating type named 'object' fails to compile, but only if you import something

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-05-17T03:27:26Z
Last change time
2022-11-18T14:34:56Z
Keywords
accepts-invalid, diagnostic
Assigned to
No Owner
Creator
Jonathan Marler

Comments

Comment #0 by johnnymarler — 2017-05-17T03:27:26Z
The following compiles today: struct object{} OR class object{] But as soon as you import anything, even just an empty module, DMD will give you the following error: Error: struct mymodule.object conflicts with import mymodule.object at mymodule.d Again, if you don't have any imports it WILL compile, but if you import anything, even an empty module then you get this odd error message. I'm not sure if D allows you to name types 'object'. If it does then this is clearly a bug in the compiler. If it doesn't then the error message should be fixed.
Comment #1 by ketmar — 2017-05-17T07:23:54Z
this is how the compiler works: when you import *something*, it implicitly imports module "object.d" (see druntime). this is core module that contains all the basic things. the reason D doesn't do it when there are no imports is simple: do allow compiling object.d itself. it is really hard to fix this error message without writing a wall of text explaining what is going on. sure, error message can be better, but it still should be concise, to not annoy expirienced users. if you can think out something good, please, make a PR (or just write it here). anything that will make error messages better is welcome! ;-)
Comment #2 by razvan.nitu1305 — 2022-11-18T14:34:56Z
This now outputs: test.d(1): Error: struct `test.object` conflicts with import `test.object` at test.d regardless if you have any imports or not. I think we can close this as WONTFIX, because the compiler automatically imports object.d (except if you compile with -betterC) so I don't see how the error message could be improved without adding a measly special case in the compiler.