inferred vs. annotated attributes

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 10 07:21:00 PDT 2016


On 09/10/2016 10:23 AM, Q. Schroll wrote:
> Is there a difference between inferred and annotated attributes?
> Example:
>
>     struct X(T)
>     {
>         this(S)(in S[] arr) // inferred pure
>         { }
>     }
>
>     void main() pure
>     {
>         X!uint mut = [ 1, 2 ]; // proves inference (cf. main is pure)
>         // immutable X!uint imm1 = [ 1, 2 ];
>         // auto imm2 = immutable X!uint([1, 2]);
>     }
>
> The commented lines yield error messages claiming the constructor cannot
> deduce function from argument types !()(int[]) immutable, however it
> can, if "pure" is explicitly annotated.
>
> Is this a bug or did I get something wrong about inference / unique
> expressions?

Bug, or at least a very reasonable enhancement request. Inferred 
attributes should work just like explicit ones.


More information about the Digitalmars-d-learn mailing list