Bug 2112 – the type of undefined variable incorrectly assumed to be int

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-05-19T20:32:00Z
Last change time
2015-06-09T01:19:24Z
Assigned to
bugzilla
Creator
bartosz

Comments

Comment #0 by bartosz — 2008-05-19T20:32:53Z
The following code compiles, and it shouldn't. int ToTypeString (T:int) () { return 1; } int ToTypeString (T:string) () { return 2; } void main () { printf("%d\n", ToTypeString!(typeof(localVariable))()); } ----------------------------- What it does have to do with is localVariable is not defined, so the compiler as part of its error recovery declared it as an int. It should have reported the error.
Comment #1 by shro8822 — 2008-05-19T23:34:13Z
that's not properly a bug. DMD seems to uses int as the default type for anything it can't figure out what do do with. However this only makes a difference /after/ it has found an error and it won't actually finish compiling in that case. I think the reason that it makes that assumption is that it lets it continue error checking some of the time. I'd be all for a dummy "undefined" type that is just a marker that is used instead as it would be less confusing.
Comment #2 by bartosz — 2008-05-20T12:02:31Z
The problem is that this code compiles without error. (Sorry, my description was just cut and paste from the exchange I had with Walter, so it's not very precise).
Comment #3 by shro8822 — 2008-05-20T12:15:49Z
Ah... Er... One more case or "Read the whole this first" (including the ReportedBy line ;) OTOH, now that I understand what you were saying, it seems the switching to type "undefined" would help more in this cases than what I thought you were saying.
Comment #4 by ary — 2008-05-20T12:22:02Z
Currently an "error" type is used in these situations, but this is just an alias of the int type. It would be very nice if a real "error" type would be returned instead. It could behave as an int, but it doesn't generate more errors. And anything that "touches" it also becomes an "error" type. That way compiler error messages would be much more cleaner: just the source of them, not the source and then a flood of other unrelated messages.
Comment #5 by bugzilla — 2008-06-22T18:56:03Z
Fixed dmd 2.015