Remix.run Logo
kazinator 2 days ago

Using older C#, a minimal program in which I have this expression:

  a.b?.c = foo
produces:

  Main.cs(19,9): error CS0131: The left-hand side of an assignment must be a variable, property or indexer
Note that it is not saying "syntax error". C# has parsed it. We have an assignment with a left hand side. The syntax already exists. There is just a semantic constraint error.

This error got replaced with code which allows that type of expression, and generates code for it rather than a diagnostic.

I can't say for sure that they did zero parser work for the feature, but it sure looks like in principle, you do not have to, for this case, given that it already parses.

(If they have a parser which handles semantic attributes in teh grammar like "assignable expression", then of course that gets adjusted.)

For reference:

  using System;

  public class A
  {
    public B b { get; set; }
  }

  public class B
  {
    public int? c { get; set; }
  }

  public class Program. 
  {
    public static void Main()
    {
      A a = new A { };
      int foo = 42;
      a.b?.c = foo;
    }
  }