Bug 7521 – Add const inference for templated method and delegate parameters

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-16T07:50:25Z
Last change time
2024-12-13T17:58:24Z
Keywords
preapproved
Assigned to
No Owner
Creator
timon.gehr
Blocks
9792
See also
https://issues.dlang.org/show_bug.cgi?id=9792
Moved to GitHub: dmd#18415 →

Comments

Comment #0 by timon.gehr — 2012-02-16T07:50:25Z
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 }
Comment #1 by timon.gehr — 2012-02-16T07:59:35Z
The original example contained some mistakes, second try: int glob; class Foo(alias a){ int x; void foo(){a(this);} static void bar(Foo x){a(x);} } void main(){ alias Foo!((a){glob=a.x;}) T; // parameter a inferred const auto foo = new immutable(T); foo.foo(); // OK, foo inferred const T.bar(foo); // OK, parameter x inferred const (T x){glob = x.x;}(foo); // ok, parameter x inferred const }
Comment #2 by timon.gehr — 2012-02-25T07:06:34Z
This probably shouldn't be done for virtual functions of templated classes.
Comment #3 by issues.dlang — 2014-02-08T16:05:39Z
Related: issue# 8407
Comment #4 by robert.schadek — 2024-12-13T17:58:24Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18415 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB