equivariant functions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 12 14:49:27 PDT 2008


Walter Bright wrote:
> If explicit, what 
> about downcast conversions? For example:
> 
>   class A : B { }
>   typeof(a) foo(A a) { return new A(); }
>   auto x = foo(b);
> 
> If we do an explicit cast, we've got null in x. I suppose that's ok.

foo will not pass typechecking. Please note that we haven't discussed 
typechecking yet.

> What about this:
> 
>    typeof(s) foo(const char[] s) { auto x = new char[3]; ...; return x; }
>    invariant(char)[] t;
>    auto s = foo(t);
> 
> now s will be unsafely typed as invariant(char)[]. Since const cannot be 
> safely cast to invariant or mutable, we might have a serious problem.

That function will not typecheck either. Let's defer the discussion on 
how to typecheck the function (I have a few good starters) to after we 
gauge interest in the solution.


Andrei



More information about the Digitalmars-d mailing list