[Issue 3833] New: pure/nothrow functions/delegates are a subtype of the nonpure/throw ones

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 18 12:58:00 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3833

           Summary: pure/nothrow functions/delegates are a subtype of the
                    nonpure/throw ones
           Product: D
           Version: 2.040
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-02-18 12:58:00 PST ---
This compiles, but it's an error because the array is mixed, &sqr is not pure:

void main() {
    double sqr(double x) { return x * x; }
    pure double psqr(double x) { return x * x; }
    pure double delegate(double)[] funcs = [&sqr, &psqr];
}


This doesn't compile, but pure functions are a subsets of impure functions:

pure real sqr1(real x) { return x * x; }
real sqr2(real x) { return x * x; }
void main() {
    real function(real x)[] funcs = [&sqr1, &sqr2];
}



While this compiles:

void main() {
    double sqr(double x) { return x * x; }
    pure double psqr(double x) { return x * x; }
    double delegate(double)[] funcs = [&sqr, &psqr];
}


The following doesn't compile, but nothrow functions are a subset of throwing
functions:

nothrow real sqr1(real x) { return x * x; }
real sqr2(real x) {
    if (x == 0) throw new Error("");
    return x * x;
}
void main() {
    real function(real x)[] funcs = [&sqr1, &sqr2];
}


(Similar things happen with "pure nothrow" functions/delegates.)

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


More information about the Digitalmars-d-bugs mailing list