C# frontend coverage

The C# constructs that the C# frontend refuses, with their diagnostic codes, Roslyn ids and examples.

The C# frontend compiles a subset of C# 15. After the C# compiler binds the documents without an error, an admission analyzer refuses each construct outside the subset with an error diagnostic. All refusals of a run are reported together, and the frontend writes no model. The overview describes the supported subset.

The same analyzer runs in the compiler, in the IDE and in morphir compile, so a refusal has one code, one message and one range everywhere. A rule cannot be turned off: #pragma warning disable, .editorconfig and NoWarn do not hide it, and a SuppressMessage attribute that names a rule is refused with MORPHIR1008. A construct that a rule refuses cannot become a model, so change the construct. The absolute IRI of a rule is the help link of its diagnostic. Codes are stable once released.

Codes

CodeRoslyn idConstruct
csharp.unsupported_loopMORPHIR1001A loop with no Morphir form is not in the Morphir subset
csharp.unsupported_mutationMORPHIR1002A change of a value is not in the Morphir subset
csharp.unsupported_dynamicMORPHIR1003dynamic is not in the Morphir subset
csharp.unsupported_mutable_propertyMORPHIR1004A property with a set accessor is not in the Morphir subset
csharp.unsupported_outside_referenceMORPHIR1005A symbol outside the fixed reference set is not in the Morphir subset
csharp.unsupported_type_kindMORPHIR1006This kind of type is not in the Morphir subset
csharp.unsupported_mutable_fieldMORPHIR1007A field that can change is not in the Morphir subset
csharp.unsupported_suppressionMORPHIR1008A suppression of a Morphir rule is not in the Morphir subset
csharp.unsupported_abstract_recordMORPHIR1009An older encoding of a sum type is not in the Morphir subset
csharp.unsupported_non_partial_equalityMORPHIR1010A type with IEEE equality must be partial

csharp.unsupported_loop

  • Roslyn id: MORPHIR1001
  • Message: The ‘…’ loop is not in the Morphir subset: it …
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_loop

Example:

static class M
{
    static int F(int[] xs)
    {
        foreach (var x in xs) { }
        return 0;
    }
}

csharp.unsupported_mutation

  • Roslyn id: MORPHIR1002
  • Message: A change of ‘…’ is not in the Morphir subset
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_mutation

Example:

static class M
{
    static int F(int a)
    {
        a = 1;
        return a;
    }
}

csharp.unsupported_dynamic

  • Roslyn id: MORPHIR1003
  • Message: ‘dynamic’ is not in the Morphir subset
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_dynamic

Example:

static class M
{
    static int F(dynamic d) => 1;
}

csharp.unsupported_mutable_property

  • Roslyn id: MORPHIR1004
  • Message: Property ‘…’ has a ‘set’ accessor
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_mutable_property

Example:

sealed record R
{
    public int X { get; set; }
}

csharp.unsupported_outside_reference

  • Roslyn id: MORPHIR1005
  • Message: ‘…’ comes from the assembly ‘…’, which is outside the fixed reference set
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_outside_reference

The analyzer reports a symbol from an assembly that the fixed reference set does not have. morphir compile cannot bind such a symbol, so the C# compiler reports it first as csharp.compiler.

csharp.unsupported_type_kind

  • Roslyn id: MORPHIR1006
  • Message: The … ‘…’ is not in the Morphir subset. Use a record, a closed record, a union, an enum or a static class.
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_type_kind

Example:

class C { }

csharp.unsupported_mutable_field

  • Roslyn id: MORPHIR1007
  • Message: Field ‘…’ can change
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_mutable_field

Example:

static class M
{
    public static int X;
}

csharp.unsupported_suppression

  • Roslyn id: MORPHIR1008
  • Message: The attribute suppresses the Morphir rule ‘…’. A construct that a Morphir rule refuses cannot become a model; change the construct.
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_suppression

Example:

[System.Diagnostics.CodeAnalysis.SuppressMessage("Morphir", "MORPHIR1001")]
static class M
{
    public static int F() => 1;
}

csharp.unsupported_abstract_record

  • Roslyn id: MORPHIR1009
  • Message: The abstract record ‘…’ is an older encoding of a sum type. Write ‘closed record …’ with ‘sealed record’ cases.
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_abstract_record

Example:

public abstract record Shape
{
    private Shape() { }
    public sealed record Circle(double Radius) : Shape;
    public sealed record Rect(double W, double H) : Shape;
}

csharp.unsupported_non_partial_equality

  • Roslyn id: MORPHIR1010
  • Message: The type ‘…’ has IEEE equality from a MorphirEquality attribute and is not partial. Add ‘partial’ to the type, because the equality members are added to it.
  • IRI: https://morphir.finos.org/rules/csharp/unsupported_non_partial_equality

Example:

[Morphir.MorphirEquality(Morphir.FloatEquality.Ieee)]
public sealed record Quote(double Value);