Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deconstruction is ambiguous

Tags:

c#

c#-7.3

I have a vector class with two deconstruction methods as follows:

public readonly struct Vector2
{
    public readonly double X, Y;

    ...

    public void Deconstruct( out double x, out double y )
    {
        x = this.X;
        y = this.Y;
    }

    public void Deconstruct( out Vector2 unitVector, out double length )
    {
        length = this.Length;
        unitVector = this / length;
    }
}

Somewhere else I have:

Vector2 foo = ...
(Vector2 dir, double len) = foo;

This gives me:

CS0121: The call is ambiguous between the following methods or properties: 'Vector2.Deconstruct(out double, out double)' and 'Vector2.Deconstruct(out Vector2, out double)'

How is this ambiguous?

Edit: Calling Deconstruct manually works fine:

foo.Deconstruct( out Vector2 dir, out double len );
like image 722
Chris Avatar asked Apr 19 '19 20:04

Chris


People also ask

What is the problem of deconstruction?

Deconstruction posits that the author and the text are entirely separate entities because there is a quasi-infinite number of interpretations of any given text, which are equal in value; therefore, giving the author prominence in light of such infinity, is incoherent, as, the origin of this is arbitrary.

What are the characteristics of deconstruction?

Deconstruction is generally presented via an analysis of specific texts. It seeks to expose, and then to subvert, the various binary oppositions that undergird our dominant ways of thinking—presence/absence, speech/writing, and so forth. Deconstruction has at least two aspects: literary and philosophical.

What do it means deconstruction?

/ˌdiː.kənˈstrʌkʃ. ən/ the act of breaking something down into its separate parts in order to understand its meaning, especially when this is different from how it was previously understood: her complex deconstruction of the Asian stereotype.

What does deconstruction mean in philosophy?

[Deconstruction] signifies a project of critical thought whose task is to locate and 'take apart' those concepts which serve as the axioms or rules for a period of thought, those concepts which command the unfolding of an entire epoch of metaphysics.


1 Answers

This is by design in C#. Overloads of Deconstruct must have different arity (number of parameters), otherwise they are ambiguous.

Pattern-matching does not have a left-hand-side. More elaborate pattern-matching scheme is to have a parenthesized list of patterns to match, and we use the number of patterns to decide which Deconstruct to use. - Neal Gafter https://github.com/dotnet/csharplang/issues/1998#issuecomment-438472660

like image 139
Asik Avatar answered Oct 12 '22 05:10

Asik