Skip to content

Deconstruct extension methods that use "in" and "ref" should work #24160

@Kentalot

Description

@Kentalot

I'm using C# 7.2 and version 15.5.3 of VS 2017 Enterprise.

Unless I'm doing something wrong, it looks like deconstruction into valuetuples using extension methods along with the in keyword for readonly pass in by reference prevents the unpacking syntax. See below.

Steps to Reproduce:

The following compiles fine:

        public static void Deconstruct(this ushort source, out byte first, out byte second)
        {
            first = (byte)(source >> 8);
            second = (byte)(source & byte.MaxValue);
        }

        public static void TestDeconstruct()
        {
            ushort source = 0;
            (var first, var second) = source;
        }

The following does not compile (using the in keyword for the source ushort):

        public static void Deconstruct(in this ushort source, out byte first, out byte second)
        {
            first = (byte)(source >> 8);
            second = (byte)(source & byte.MaxValue);
        }

        public static void TestDeconstruct()
        {
            ushort source = 0;
            (var first, var second) = source;
        }

Expected Behavior:
Both should compile fine and the second example that currently does not compile should also pass in the source ushort by reference.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions