This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 16376 - Evaluator.Evaluate Failure to use Gotos when compiling a Func to be returned
: Evaluator.Evaluate Failure to use Gotos when compiling a Func to be returned
Status: RESOLVED FIXED
Product: Compilers
Classification: Mono
Component: C#
: 3.2.x
: PC Windows
: --- normal
: ---
Assigned To: Marek Safar
:
:
:
  Show dependency treegraph
 
Reported: 2013-11-20 18:16 EST by benb7760
Modified: 2013-12-11 14:04 EST (History)
2 users (show)

See Also:
Tags:


Attachments
Visual Studio project (2012) showing the bug (2.71 MB, application/zip)
2013-11-20 18:16 EST, benb7760
Details

Description benb7760 2013-11-20 18:16:59 EST
Created attachment 5490 [details]
Visual Studio project (2012) showing the bug

Attached is a VS2012 project showing the bug

Using Mono.CSharp as downloaded from Nuget

When Evaluating a Func, if the body contains Gotos, an exception occurs; Bad
label content in ILGenerator

       Func<Dictionary<string, object>, dynamic, LogWrapperMethod,
LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod,
AddResultWrapperMethod, int> a = new Func<Dictionary<string, object>, dynamic,
LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod,
ExcWrapperMethod, AddResultWrapperMethod, int>((parameters, self, debug, log,
warn, error, exception, addResult) =>
        {

            Console.WriteLine("beforegoto");
            goto Ben;
        Ben:
            Console.WriteLine("gotoResult");
            return 0;

        });
I am getting InternalErrorException ((1,1): ) The InnerException is

Bad label content in ILGenerator

at System.Reflection.Emit.ILGenerator.GetLabelPos(Label lbl)
at System.Reflection.Emit.ILGenerator.BakeByteArray()
at System.Reflection.Emit.MethodBuilder.CreateMethodBodyHelper(ILGenerator il)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at Mono.CSharp.TypeDefinition.CloseContainer()
I am setting up the Evaluator (_e) as such

        _settings = new CompilerSettings
                        {
                            EnhancedWarnings = true,
                            Stacktrace = true,
                            ShowFullPaths = true,
                            Timestamps = true,
                            Optimize = true,
                            AssemblyReferences = new List<string>
                                                     {
                                                         "Microsoft.CSharp.dll"
                                                     },
                        };
        _ctx = new CompilerContext(_settings, new Reporter());
        _e = new Evaluator(_ctx);
        _e.Run("using System;");
        _e.Run("using System.Collections.Generic;");
        _e.Run("using System.Dynamic;");
        _e.Run("using System.Linq;");
        _e.Run("using System.Text.RegularExpressions;");
Comment 1 Marek Safar 2013-12-11 14:04:18 EST
Fixed in master

Note You need to log in before you can comment on or make changes to this bug.