Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

[VS2015] ccrewrite fails when Expression is used in a precondition #133

@SergeyTeplyakov

Description

@SergeyTeplyakov

Following code works fine in VS2013 but fails to compile in VS2015:

public class WithExpressions
{
    public void A(bool expected)
    {
        Contract.Requires(P1<string, string>(x => x, expected));
    }

    public void A2(bool expected)
    {
        Contract.Requires(P1<string, string>(x => x, expected));
        Contract.Requires(P1<string, string>(x => x, expected));
    }

    public void A3(bool expected)
    {
        Contract.Requires(P1<string, string>(x => x, expected));
        bool r = P1<string, string>(x => x, expected);
    }        
}

The error from ccrewrite is:

Tests\RoslynCompatibility\ExpressionsInRequires.cs(36,3) : error CC1040: Reuse of existing local variable 'local0' in contract.
Tests\RoslynCompatibility\ExpressionsInRequires.cs(41,3) : error CC1025: After contract block, found use of local variable 'local1' defined in contract block
Tests\RoslynCompatibility\ExpressionsInRequires.cs(30,3) : error CC1004: Malformed contract. Found Requires after assignment in method 'Tests.Sources.WithExpressions.A(System.Boolean)'.

Please note, that the error would happen only for Expression<Func<..>> but not for lambda expression convertible to Func<..>.

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions