Skip to content

in and out arguments should be disallowed in __arglist #22455

@VSadov

Description

@VSadov

varargs should disallow out and in arguments. There is no way the calee can express its part of the contract.

We currently allow both and out was allowed in old compiler versions too. We should disallow both.

Arguably it would be a breaking change for out, but it is very unlikely it would affect real code.

Example:

    class Program
    {
        static void Main(string[] args)
        {
            int unassigned;
            int doNotChange = 42;

            Test(__arglist(out unassigned, in doNotChange));  // <--  out?   in?  really?

            System.Console.WriteLine(unassigned);
            System.Console.WriteLine(doNotChange);
        }

        static void Test(__arglist)
        {
            var args = new ArgIterator(__arglist);

            // leave unassigned unassigned
            ref var unassigned = ref __refvalue(args.GetNextArg(), int);

            // assign junk to doNotChange
            ref var doNotChange = ref __refvalue(args.GetNextArg(), int);
            doNotChange = unassigned;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions