www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7838] New: Give some error messages for wrong ranges

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

           Summary: Give some error messages for wrong ranges
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



I'd like DMD to give some error messages for wrong definitions of ranges, like
in this case:


struct Powers {
    int m;
    BigInt n;
    this(int m_) { this.m = m_; }
    const bool empty = false;
    BigInt front() { return n ^^ m; }
    void popFront() { n += 1; }
}


It looks correct, but it's wrong. ElementType!Powers is void.

The correct code (a  property was missing):

struct Powers {
    int m;
    BigInt n;
    this(int m_) { this.m = m_; }
    const bool empty = false;
     property BigInt front() { return n ^^ m; }
    void popFront() { n += 1; }
}

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


Matt Peterson <revcompgeek gmail.com> changed:

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



PDT ---
My understanding is that you would usually put a static assert with
isInputRange, or a more specific template from std.range immediately after the
struct. How is DMD supposed to know that that struct is suppose to be a range
otherwise?

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





 My understanding is that you would usually put a static assert with
 isInputRange, or a more specific template from std.range immediately after the
 struct.
This is an example program: import std.range, std.bigint; struct Powers { int m; BigInt n; this(int m_) { this.m = m_; } const bool empty = false; BigInt front() { return n ^^ m; } void popFront() { n += 1; } } static assert(isInputRange!Powers); void main() {} If I compile it with DMD 2.059beta: ...>dmd -property -run temp.d temp.d(10): Error: static assert (isInputRange!(Powers)) is false So it gives me no hint where the problem is. A built-in error message is supposed to be more precise. As alternative, maybe there is a way to add focused error messages inside a isInputRangeVerify template to be used to verify that an input range is correct, that uses pragma(msg) or better ctWriteln.
 How is DMD supposed to know that that struct is suppose to be a range
 otherwise?
I see, it's a problem. So here we are talking more about a probabilistic compiler tip. If the class/struct contains a popFront and front and empty methods then the programmer probably meants it to be a range. Thank you for your answer. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7838




PDT ---
Yeah, I think the best solution is to add verifyInputRange etc. templates to
std.range, where each criteria is checked by a separate static assert. It's
just a little ugly because there will end up being nearly duplicate templates
for all the different range types.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 06 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7838





 It's just a little ugly because there will end up being nearly
 duplicate templates for all the different range types.
I think putting such test code inside DMD itself doesn't reduce the overall complexity a lot... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 06 2012