Unity编译器不完全支持命名参数吗?

时间:2015-07-06 10:53:31

标签: c# unity3d compiler-errors

以下代码在Visual Studio中编译得很好,但在Unity(4.6.x)中它会产生编译错误:

public class ErrorTest 
{
    void DoSomething(bool a = true, bool f = true) {  }
    void DoSomething(int b, bool f = true) {  }
    public void SomeMethod()
    {
       DoSomething(f: false);
    }
}

对DoSomething的调用是编译器窒息的原因。问题是为什么,确实没有歧义。

Unity扼流圈时的控制台输出:

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: Mono.CSharp.InternalErrorException: Internal error

  at Mono.CSharp.MethodGroupExpr.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, System.Reflection.MethodBase& method, System.Boolean& params_expanded_form) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& Arguments, Boolean may_fail, Location loc) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in <filename unknown>:0 

1 个答案:

答案 0 :(得分:0)

There was/is apparently a bug结合命名空间和默认参数的使用导致了这样的内部错误。据称它在4.5中被修正,但据称之前已经修复过的评论。您可以尝试在类中删除名称空间声明作为实验,以查看您遇到的错误是什么。