www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5073] New: wrong file name in error message for "voids have no value" inside alias templates (affects std.algorithm.map)

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

           Summary: wrong file name in error message for "voids have no
                    value" inside alias templates (affects
                    std.algorithm.map)
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: sandford jhu.edu



There seems to be an issue with the reported filename for alias templates that
create a variable of type void. Here is a test case:

using DMD 2.049:

import std.algorithm;
void main(string[] args) {
    auto foobar  = map!( (int i){} )([0]); // using a named delegate also
errors
}

results in the error message

hello.d, Line 119
Error: variable hello.main.Map!(__dgliteral1,int[]).Map._cache voids have no
value

Line 119 of std.algorithm (part of the Map struct):
Unqual!ElementType _cache;

This may be related to issue 2180.

Here is a reduced test case that gives a slightly better set of error messages
than the std.algorithm example:

hello.d:
import std.stdio: writeln;
import goodbye;

void main(string[] args) {
    auto foobar  = map!( (int i){} )(5);
    return;
}

goodbye.d:
module goodbye;







// line 9
template map(fun...)            //
{
    auto map(Range)(Range r)
    {
        return Map!(fun)(r);    // line 14, must instantiate with fun or r not
Range
    }
}

struct Map(alias fun) {         // Must be an alias template
    void _cache;                // line 19
}


Error messages produced:

hello.d Line 19
Error: variable hello.main.Map!(delegate void(int i)
hello.d Line 14
Error: template instance hello.main.Map!(delegate void(int i)
hello.d Line 5
instantiated from here: map!(int)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 18 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073


Rob Jacques <sandford jhu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, wrong-code
           Severity|normal                      |regression



In DMD 2.051, this error message has ceased to be generated for certain inputs
and instead a runtime access violation is generated. Here is a reduced test
case:

struct Bar(T) {
    T x;
    Bar dot(Bar b) { return Bar(x+b.x); }
}

void main(string[] args) {
    Bar!real   b;
    Bar!real[] data = new Bar!real[5];
    auto foobar  = map!((a){return a.dot(b); })(data);
    return;
}

Here is a modified to std.algorithm.map that works arounds this specific bug:

template map(fun...) {
    auto map(Range)(Range r) {
        static if (fun.length > 1) {
            return Map!( unaryFun!( adjoin!(staticMap!(unaryFun, fun)) ), Range
)(r);
        } else {
            static if( is(typeof(fun[0]) == delegate) ) {
                return Map!(fun, Range)(fun[0],r);
            } else {
                return Map!(unaryFun!fun, Range)(r);
            }
        }
    }
}

struct Map(alias fun, Range) if (isInputRange!(Range))
{
    Unqual!Range _input;
    static if( is(typeof(fun) == delegate) ) {
        typeof(fun) _fun;
        this(typeof(fun) dg, Range input) { _fun = dg;  _input = input; }
    } else {
        alias fun _fun;
        this(Range input) { _input = input; }
    }


    alias typeof({ return _fun(.ElementType!(Range).init); }()) ElementType;

    static if (isBidirectionalRange!(Range)) {
         property ElementType back()    { return  _fun(_input.back); }
                  void        popBack() {         _input.popBack;    }
    }

    // Propagate infinite-ness.
    static if (isInfinite!Range)  {
        enum bool empty = false;
    } else {
         property bool empty() { return _input.empty; }
    }

    void popFront() { _input.popFront; }

     property ElementType front() { return _fun(_input.front); }

    static if (isRandomAccessRange!Range)
    {
        ElementType opIndex(size_t index)
        {
            return _fun(_input[index]);
        }
    }

    // hasLength is busted, Bug 2873
    static if (is(typeof(_input.length) : size_t)
        || is(typeof(_input.length()) : size_t))
    {
         property size_t length()
        {
            return _input.length;
        }
    }

    static if (hasSlicing!(Range)) {
        typeof(this) opSlice(size_t lowerBound, size_t upperBound) {
            auto result = this;
            result._input = result._input[lowerBound..upperBound];
            return result;
        }
    }

    static if (isForwardRange!Range)
     property Map save()
    {
        auto result = this;
        result._input = result._input.save;
        return result;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 05 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073




14:18:23 PST ---

 In DMD 2.051, this error message has ceased to be generated for certain inputs
 and instead a runtime access violation is generated. Here is a reduced test
 case:
 
 struct Bar(T) {
     T x;
     Bar dot(Bar b) { return Bar(x+b.x); }
 }
 
 void main(string[] args) {
     Bar!real   b;
     Bar!real[] data = new Bar!real[5];
     auto foobar  = map!((a){return a.dot(b); })(data);
     return;
 }
I just tried the example above with 2.051. It compiles and runs. Could you please provide a different example? Thanks! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 16 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073






 In DMD 2.051, this error message has ceased to be generated for certain inputs
 and instead a runtime access violation is generated. Here is a reduced test
 case:
 
 struct Bar(T) {
     T x;
     Bar dot(Bar b) { return Bar(x+b.x); }
 }
 
 void main(string[] args) {
     Bar!real   b;
     Bar!real[] data = new Bar!real[5];
     auto foobar  = map!((a){return a.dot(b); })(data);
     return;
 }
I just tried the example above with 2.051. It compiles and runs. Could you please provide a different example? Thanks!
While it does compile on my system, when it runs it causes an "object.Error: Access Violation". I'm on an Intel Core-i7 920 (Quad core) running Windows 7 64-bit. Just to double check, here is a more extensive version of the same test which verifies the map is run correctly. void main(string[] args) { Bar!real b = Bar!real(5); Bar!real[] data = new Bar!real[5]; foreach(i,ref d;data) d.x = i; Bar!real[] expected = new Bar!real[5]; foreach(i,ref e;expected) e = data[i].dot(b); auto foobar = map!((a){return a.dot(b); })(data); foreach(z;zip(foobar,expected)) assert(z[0].x == z[1].x); return; } Also, does the example from my first post compile & run for you? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 20 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073




Minor update to handle fixed sized arrays properly.

template map(fun...) {
    auto map(Range)(Range r) {
        static if (fun.length > 1) {
            return Map!(unaryFun!(adjoin!(staticMap!(unaryFun,fun))),Range)(r);
        } else {
            static if( is(typeof(fun[0]) == delegate) ) {
                return Map!(fun, Range)(fun[0],r);
            } static if( is(Range E:E[]) ) {
                return Map!(unaryFun!fun, E[])(r[]);
            } else {
                return Map!(unaryFun!fun, Range)(r);
            }
        }
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 19 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073




*oops* forgot the else statements

template map(fun...) {
    auto map(Range)(Range r) {
        static if (fun.length > 1) {
            return Map!(unaryFun!(adjoin!(staticMap!(unaryFun,fun))),Range)(r);
        } else {
            static if( is(typeof(fun[0]) == delegate) ) {
                return Map!(fun, Range)(fun[0],r);
            } else static if( is(typeof(unaryFun!fun) == delegate) ) {
                return Map!(unaryFun!fun, Range)(unaryFun!fun,r);
            } else static if( is(Range E:E[]) ) {
                return Map!(unaryFun!fun, E[])(r[]);
            } else {
                return Map!(unaryFun!fun, Range)(r);
            }
        }
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 19 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



None of these examples fail for me with dmd 2.054 head on win32.  Can anybody
reproduce this with a current dmd?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 03 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073




I've had trouble with map in DMD 2.053 and fixed it with this patch. I've even
updated the patch to the new internal struct style being used in std.algorithm.
(not-yet posted). But this has been due to map not handling fixed sized arrays:

    ubyte[12] datum;
    map!"a"(datum);

Which as of this evening's SVN, is still true. I don't know about the original
code which spawned this bug report, but once fixed-sized arrays work, I can
re-test it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 03 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc




 I've had trouble with map in DMD 2.053 and fixed it with this patch. I've even
 updated the patch to the new internal struct style being used in std.algorithm.
 (not-yet posted). But this has been due to map not handling fixed sized arrays:
 
     ubyte[12] datum;
     map!"a"(datum);
 
 Which as of this evening's SVN, is still true. I don't know about the original
 code which spawned this bug report, but once fixed-sized arrays work, I can
 re-test it.
I'd like map to work on fixed-size arrays too, but I think Andrei doesn't want this to be fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 03 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5073


Rob Jacques <sandford jhu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |WORKSFORME



I added a new bug report for the fixed-sized array issue: Issue 6256. But
otherwise, this appears to be fixed as of DMD 2.053.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 05 2011