C# frontend coverage
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
| Code | Roslyn id | Construct |
|---|---|---|
csharp.unsupported_loop | MORPHIR1001 | A loop with no Morphir form is not in the Morphir subset |
csharp.unsupported_mutation | MORPHIR1002 | A change of a value is not in the Morphir subset |
csharp.unsupported_dynamic | MORPHIR1003 | dynamic is not in the Morphir subset |
csharp.unsupported_mutable_property | MORPHIR1004 | A property with a set accessor is not in the Morphir subset |
csharp.unsupported_outside_reference | MORPHIR1005 | A symbol outside the fixed reference set is not in the Morphir subset |
csharp.unsupported_type_kind | MORPHIR1006 | This kind of type is not in the Morphir subset |
csharp.unsupported_mutable_field | MORPHIR1007 | A field that can change is not in the Morphir subset |
csharp.unsupported_suppression | MORPHIR1008 | A suppression of a Morphir rule is not in the Morphir subset |
csharp.unsupported_abstract_record | MORPHIR1009 | An older encoding of a sum type is not in the Morphir subset |
csharp.unsupported_non_partial_equality | MORPHIR1010 | A 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);
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.