Bug 6005 – Type name and variable name don't clash

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-05-15T05:21:23Z
Last change time
2024-12-13T17:55:13Z
Keywords
diagnostic
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#18340 →

Comments

Comment #0 by bearophile_hugs — 2011-05-15T05:21:23Z
This is D code adapted from a blog post about C language: http://eli.thegreenplace.net/2011/05/02/the-context-sensitivity-of-c%E2%80%99s-grammar-revisited/ http://www.reddit.com/r/programming/comments/h23h3/the_context_sensitivity_of_cs_grammar_revisited/ Three little D2 programs that compile with no errors. Similar code is allowed in C too: ------------ alias int Foo; void foo() { Foo bar; float Foo; } void main() {} ------------ alias int Foo; void foo() { Foo Foo; int bar = Foo + 2; assert (bar == 2); } void main() {} ------------ alias char Foo; void foo() { int bar = Foo.sizeof, Foo, spam = Foo.sizeof; assert(bar == 1); assert(spam == 4); } void main() {} ------------ Is it OK to keep allowing such kind of code in D2 too? Or is it better to statically forbid it? A disadvantage of statically disallowing it is the breakage of some valid C code. On the other hand I don't want to find code like that in D programs.
Comment #1 by robert.schadek — 2024-12-13T17:55:13Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18340 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB