Skip to content

12.7.5 and 12.18.2 Member access evaluation order for assignments #401

@gafter

Description

@gafter

This is a companion issue to #169

12.7.5 (member access) suggests that evaluating a member access expression performs a nullity check.

12.18.2 (simple assignment) states for an assignment x = y:

  • If x is classified as a variable:
    • x is evaluated to produce the variable.
    • y is evaluated and, if required, converted to the type of x through an implicit conversion (§12.2).

That all sounds fine, but my understanding of reality is that the nullity check is only performed after y is evaluated. Sample code to show that...

public class Q {
    public int x;

    public static void Main() {
        Q q = null;
        q.x = SideEffect();
    }
    
    public static int SideEffect()
    {
        System.Console.WriteLine("SideEffect");
        return 2;
    }
}

Assigning to Mads initially as he has been assigned #169

Metadata

Metadata

Assignees

Labels

status: gnarlyThis issue is likely to require very significant work to resolvetype: bugThe Standard does not describe the language as intended or implemented

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions