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.

NullReferenceException with lambda in requires of contract class in VS2015 #49

@billings7

Description

@billings7

Ccrewrite fails with a NullReferenceException when a contract class contains a requires that has a lambda expression when compiled in Visual Studio 2015.

For example:

[ContractClass(typeof(FooContracts))]
public interface IFoo
{
    void Method(params string[] strings);
}

[ContractClassFor(typeof(IFoo))]
public abstract class FooContracts : IFoo
{
    public void Method(params string[] strings)
    {
        Contract.Requires(Contract.ForAll(strings, s => s.Length > 0));
    }
}

public class Foo : IFoo
{
    public void Method(params string[] strings)
    {
        Console.WriteLine(string.Join(", ", strings));
    }
}

Perform Runtime Contract Checking has to be enabled and not None.

I believe it is due to a change in how lambdas and closures are compiled by Rosyln. Something that may be related is a Debug.Assert failing in Foxtrot\Foxtrot\Utility.cs line 2320

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions