Bug 16376 - Evaluator.Evaluate Failure to use Gotos when compiling a Func to be returned
Summary: Evaluator.Evaluate Failure to use Gotos when compiling a Func to be returned
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 3.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-11-20 18:16 UTC by benb7760
Modified: 2013-12-11 14:04 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


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


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description benb7760 2013-11-20 18:16:59 UTC
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 UTC
Fixed in master