开发者

C# Parser Bug on delegate? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

'Delegate 'System.Action' does not take 0 arguments.' Is this a C# compiler bug (lambdas + two projects)?

When I was doing a testing framework that used heavy lambda usage I thing I stumbled on a parser bug.

public class CSpecTestRunnerSpec : CSpecFacade<CSpecTestRunner>
{
    public CSpecTestRunnerSpec()
        : base(new CSpecTestRunner())
    {
        CreateOperations();
    }

    private MyClassSpec myClassSpec;
    private DescribeAll run_on_type;

    protected override void BeforeOperation()
    {
        myClassSpec = new MyClassSpec();
    }

    private void CreateOperations()
    {
        run_on_type =
           (@it, @do) =>
           {
               @it("Runs all of the operations contained in a type");
               @do.RunTestOnType(myClassSpec.GetType());
           };
    }

DescribeAll delegate comes from the base class and it's interface looks like so:

EDIT the code looks like so:

public delegate void DescribeAll(Action<string> description, TClass objSpec);

The exception I'm getting is "Delegate Action does not take 1 arguments" But it totally does! and after adding a dummy delegate to code of my class:

    private Action<string> dummy;

It started to work. :-)

By contrast the same code works with开发者_开发知识库out errors in mono without the dummy delegate it was tested on multiple machines with NET 3.5 and 4.0.

So my question is, is this a bug on the compiler side or my side?, and how to resolve the issue?

p.s the framework is on codeplex so you can get the full code and test it yourself.


UPDATE:

The bug has been fixed in C# 5. Apologies again for the inconvenience, and thanks for the report.


That is a known bug in the compiler, though it is not in the parser; it's in the interaction between the semantic analyzer and the metadata import cache. My analysis of the bug is here:

'Delegate 'System.Action' does not take 0 arguments.' Is this a C# compiler bug (lambdas + two projects)?

This one was my fault; I apologize for the inconvenience. We'll try to get it fixed for the next version.


There is a delegate type Action that takes no arguments. I think you want Action<T>

public delegate void DescribeAll(Action<string> description, TClass objSpec);

or

public delegate void DescribeAll(Action<object> description, TClass objSpec);

or

public delegate void DescribeAll<T>(Action<T> description, TClass objSpec);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜