www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2112] New: the type of undefined variable incorrectly assumed to be int

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2112

           Summary: the type of undefined variable incorrectly assumed to be
                    int
           Product: D
           Version: 2.013
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: bartosz relisoft.com


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.


-- 
May 19 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2112





------- Comment #1 from shro8822 vandals.uidaho.edu  2008-05-19 23:34 -------
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.


-- 
May 19 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2112





------- Comment #2 from bartosz relisoft.com  2008-05-20 12:02 -------
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).


-- 
May 20 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2112





------- Comment #3 from shro8822 vandals.uidaho.edu  2008-05-20 12:15 -------
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.


-- 
May 20 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2112





------- Comment #4 from ary esperanto.org.ar  2008-05-20 12:22 -------
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.


-- 
May 20 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2112


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #5 from bugzilla digitalmars.com  2008-06-22 18:56 -------
Fixed dmd 2.015


-- 
Jun 22 2008