[Issue 7521] New: Add const inference for templated method and delegate parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 16 07:50:27 PST 2012


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

           Summary: Add const inference for templated method and delegate
                    parameters
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: timon.gehr at gmx.ch


--- Comment #0 from timon.gehr at gmx.ch 2012-02-16 07:50:25 PST ---
Not only pure/nothrow/@safe should be inferred, but const on parameters and
methods should be inferred too. This increases the expressiveness of alias
parameters and is required for making templates const correct. Inferring const
for delegate parameters reduces the annotation overhead and makes treatment of
template delegate literals uniform with normal delegate literals.

IOW, the following code should compile:

int glob;

class Foo(alias a){
    int x;
    void foo(){a(this);}
    static int bar(Foo x){return a(foo);}
}

void main(){
    alias Foo!((p){glob=p.x;}) T; // parameter p inferred const
    auto foo = new immutable(T);
    foo.foo();  // OK, T.foo inferred const
    T.bar(foo); // OK, parameter x of T.bar inferred const
    (T x){glob = x.x;}(foo); // OK, parameter x inferred const
}

-- 
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