Bug 321906 (MONO79197) - [GMCS] anonymous delegates which return a value are miscompiled
Summary: [GMCS] anonymous delegates which return a value are miscompiled
Status: RESOLVED FIXED
Alias: MONO79197
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Miguel de Icaza
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-28 20:34 UTC by Jonathan Pryor
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:07:49 UTC


---- Reported by jonpryor@vt.edu 2006-08-28 13:34:00 MST ----

Please fill in this template when reporting a bug, unless you know what you
are doing.
Description of Problem:

gmcs doesn't like compiling anonymous delegates which return a value.

Steps to reproduce the problem:
1. Take the following code, saving it to `ad.cs':

  // fun w/ anonymous delegates!
  using System;
  using System.Collections.Generic;
  using System.Text.RegularExpressions;

  class Test {
    delegate bool CommandHandler (string line);

    static Dictionary <string, CommandHandler> commands;
    static Test ()
    {
      commands = new Dictionary <string, CommandHandler> ();
      commands ["help"] = delegate (string line) {
        Console.WriteLine ("insert help text here");
        return true;
      };
    }

    public static void Main ()
    {
      Console.WriteLine ("Welcome to the silly command interpreter.");
      Console.WriteLine ("Supported commands: ");
      foreach (string key in commands.Keys)
        Console.WriteLine ("\t" + key);
      Regex r = new Regex (@"^([\w]+)");
      string line;
      while ((line = Console.In.ReadLine ()) != null) {
        Match m = r.Match (line);
        if (m.Success) {
          string command = m.Groups [0].Value;
          if (commands.ContainsKey (command)) {
            commands [command] (line);
          }
          else {
            Console.WriteLine ("invalid command `{0}' in line: {1}", 
              command, line);
          }
        }
        else {
          Console.WriteLine ("no command specified: " + line);
        }
      }
    }
  }

2. Compile it:

  $ gmcs ad.cs
  ad.cs(14,9): warning CS0162: Unreachable code detected
  Compilation succeeded - 1 warning(s)

Note that gmcs gives a warning about "unreachable" code, which is
incorrect, there is no unreachable code.

3. Run it:

  $ mono ad.exe
  Welcome to the silly command interpreter.
  Supported commands:
        help

and enter random \n-separated text:

  foo bar
  invalid command `foo' in line: foo bar

Enter a valid command:

  help

And note that _no_ output is generated.  The anonymous delegate handler for
the `help' command is not invoked.

Actual Results:

No output.

Expected Results:

The message "insert help text here" displayed to stdout.

How often does this happen? 

Always.

Additional Information:



---- Additional Comments From jonpryor@vt.edu 2006-08-28 13:35:59 MST ----

This only happens if the CommandHandler delegate has a return type. 
If there is no return type, then everything works as expected.



---- Additional Comments From miguel@ximian.com 2006-08-29 18:41:33 MST ----

This works for me with Mono 1.1.17, what version were you using?




---- Additional Comments From jonpryor@vt.edu 2006-08-29 21:36:49 MST ----

I was using Mono 1.1.13.7 and whatever svn build I had around the time
of 1.1.16.

Good to know that 1.1.17 has the fix.


Unknown operating system unknown. Setting to default OS "Other".