Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It looks like LoweredDynamicOperationFactory.GetReceiverRefKind hasn't been adjusted for ref returns #68063

Closed
AlekseyTs opened this issue May 2, 2023 · 1 comment · Fixed by #70676

Comments

@AlekseyTs
Copy link
Contributor

It looks like ref returning properties and methods are not getting special treatment:

        // If we have a struct calling object, then we need to pass it by ref, provided
        // that it was an Lvalue. For instance,
        //     Struct s = ...; dynamic d = ...;
        //     s.M(d); // becomes Site(ref s, d)
        // however
        //     dynamic d = ...;
        //     GetS().M(d); // becomes Site(GetS(), d) without ref on the target obj arg
        internal static RefKind GetReceiverRefKind(BoundExpression loweredReceiver)
        {
            Debug.Assert(loweredReceiver.Type is { });
            if (!loweredReceiver.Type.IsValueType)
            {
                return RefKind.None;
            }

            switch (loweredReceiver.Kind)
            {
                case BoundKind.Parameter:
                    Debug.Assert(!LocalRewriter.IsCapturedPrimaryConstructorParameter(loweredReceiver));
                    goto case BoundKind.Local;

                case BoundKind.Local:
                case BoundKind.ArrayAccess:
                case BoundKind.ThisReference:
                case BoundKind.PointerIndirectionOperator:
                case BoundKind.PointerElementAccess:
                case BoundKind.RefValueOperator:
                    return RefKind.Ref;

                case BoundKind.BaseReference:
                // base dynamic dispatch is not supported, an error has already been reported
                case BoundKind.TypeExpression:
                    throw ExceptionUtilities.UnexpectedValue(loweredReceiver.Kind);
            }

            return RefKind.None;
        }
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label May 2, 2023
@jcouv jcouv changed the title It looks like LoweredDynamicOperationFactory.GetReceiverRefKind hasn't bee adjusted for ref returns It looks like LoweredDynamicOperationFactory.GetReceiverRefKind hasn't been adjusted for ref returns May 4, 2023
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label May 4, 2023
@jcouv jcouv added this to the C# 12.0 milestone May 4, 2023
@jcouv
Copy link
Member

jcouv commented May 4, 2023

Assigned to @cston for investigation and triage during C# 12 timeframe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants