marinasundstrom / CodeContractsTest

Experimental - Code Contracts for C#
3 stars 0 forks source link

`RequiresAttribute` expression syntax speculations #1

Open Rekkonnect opened 2 years ago

Rekkonnect commented 2 years ago

Relational pattern expression trees cannot be encoded in attributes (as of yet). The language does not provide any consumable constructs to represent relational patterns either.

This means that relational pattern expressions have to be parsed with a custom parser, and internally represented with a custom expression tree construct.

If expression trees are not intended to be parsed, flexibilty around requirements is lost, restricting to simple patterns like >= 0 and < 42 is inevitable.

marinasundstrom commented 2 years ago

Yes, I am aware of this. That is the reason for encoding it as strings.

The analyzer has to construct a complete expression and tell the Roslyn C# compiler to validate against that expression. It is about the constraints.

This check would just be at compile time. To compare the constraints of a source (Ensures) when passed into target (Requires).

Code contracts turns out to be limited and not to be that helpful in the bigger scheme of things.

You cannot do complex evaluations at compile-time.