DIP66 - Multiple alias this
IgorStepanov via Digitalmars-d
digitalmars-d at puremagic.com
Fri Oct 10 15:20:55 PDT 2014
On Friday, 10 October 2014 at 22:05:18 UTC, Timon Gehr wrote:
> On 10/10/2014 07:09 PM, IgorStepanov wrote:
>> I've created DIP for my pull request.
>> DIP: http://wiki.dlang.org/DIP66
>> PR: https://github.com/D-Programming-Language/dmd/pull/3998
>>
>> Please, comment it.
>
> - "C c;
> int i = c; //Error: c.a.i vs c.b.i
>
> static assert(is(C : int)); //Ok, because C is subtype of int
> anyway."
>
> So now we can have 'subtypes' whose instances cannot be stored
> in variables of the 'base type'?
C++ allowed subtypes, which can not be casted to the base type
(inheritance of two identical, non-virtual base classes).
Ok, I've wrote my position, understood your and wait the decision
of the arbitrator:)
> Such behaviour is inconsistent with both the reference
> implementation and the documentation (and the two happen to be
> mutually inconsistent on how 'is(:)' should behave as well. :o)
> )
>
>
> - "The following pseudo-code illustrates this: [...] Finally,
> if resultSet contains only one candidate, the compiler will
> accept it."
>
> This process might very well never terminate but it could
> terminate in more cases if it did something better than the
> naive brute-force search. I.e. either report cycles or don't
> keep exploring around cycles, but just looping indefinitely on
> cycles like the following is IMO not a good course of action:
>
> struct S{
> alias get this;
> T get(){ return T.init; }
> }
> struct T{
> alias get this;
> S get(){ return S.init; }
> int x;
> alias x this;
> }
>
> void main(){
> S s;
> int x=s;
> }
This case described in DIP below.
Recursion tree will be like:
s.get
s.get.get ->return, because T is already visited
s.x -> win
> Furthermore, the following code compiles now, but doesn't under
> the approach described in the DIP. Is this an actual regression
> your pull introduces or is there a bug in the pseudocode?:
>
> class A{
> alias x this;
> int x;
> }
>
> class B: A{
> alias y this;
> int y;
> }
>
> void main(){
> int x = new B();
> }
>
> The same issue also needs to be considered if A and B are
> structs instead and B has an additional alias this to an A (the
> solution might also be part of a fix for the cycle issue).
>
> - "If resultSet contains more then one candidates, the compiler
> raises an error."
struct A
{
short s;
alias s this;
}
struct B
{
int i;
alias i this;
}
struct C
{
A a;
B b;
alias a this;
alias b this;
}
long l = C(); //What do you suggest?
More information about the Digitalmars-d
mailing list