Why simple code using Rebindable doesn't compile ?
Alex Parrill via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 30 14:32:46 PDT 2016
On Monday, 30 May 2016 at 10:09:19 UTC, chmike wrote:
> This code compile, but array appending doesn't work
>
> ----
> alias Rebindable!(immutable(InfoImpl)) Info;
>
> class InfoImpl
> {
> void foo() {}
> static immutable(InfoImpl) info()
> {
> __gshared immutable InfoImpl x = new immutable InfoImpl;
> return x;
> }
> }
>
>
> void main()
> {
> Info t = Info.info;
> Info[] a;
> //a ~= Info.info; <-- KO Compiler Error
> a ~= rebindable(Info.info); // Ok
> }
> -----
>
> Why can't info() return a Rebindable!(immutable(InfoImpl)) ?
What do you mean? `info` returns an `immutable(InfoImpl)`, not a
`Rebindable!(immutable(InfoImpl))`. Rebindable doesn't apply
itself to the return types of the methods of the return types
(there's no reason to).
More information about the Digitalmars-d-learn
mailing list