[Mono-bugs] [Bug 424064] New: [gmcs] Internal Compiler Error when Query Expression Pattern is implemented via instance members

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Sep 6 11:13:52 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=424064


           Summary: [gmcs] Internal Compiler Error when Query Expression
                    Pattern is implemented via instance members
           Product: Mono: Compilers
           Version: SVN
          Platform: x86-64
        OS/Version: openSUSE 11.0
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: jpryor at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


When implementing the Query Expression Pattern (to permit use of query
expressions against new types), gmcs emits an Internal compiler error if the
Query Expression Pattern is implemented via instance methods.

If the Query Expression Pattern is instead implemented as extension methods, no
error is reported.

To see the error, compile the following source:

  using System;

  class Maybe<T>
  {
      public readonly static Maybe<T> Nothing = new Maybe<T>();
      public T Value { get; private set; }
      public bool HasValue { get; private set; }
      Maybe()
      {
          HasValue = false;
      }
      public Maybe(T value)
      {
          Value = value;
          HasValue = true;
      }

      public override string ToString()
      {
        if (HasValue)
          return Value.ToString();
        return string.Empty;
      }

      public Maybe<U> SelectMany<U>(Func<T, Maybe<U>> k)
      {
          if (!HasValue)
              return Maybe<U>.Nothing;
          return k(Value);
      }

      public Maybe<V> SelectMany<U, V>(
          Func<T, Maybe<U>> selector, 
          Func<T,U,V> resultSelector)
      {
          if (!HasValue)
              return Maybe<V>.Nothing;
          Maybe<U> n = selector (Value);
          if (!n.HasValue)
              return Maybe<V>.Nothing;
          return resultSelector(Value, n.Value).ToMaybe();
      }
  }

  static class MaybeExtensions {
      public static Maybe<T> ToMaybe<T>(this T value)
      {
          return new Maybe<T>(value);
      }
  }

  class Test {
      public static void Main ()
      {
          var r = from x in 5.ToMaybe()
                  from y in Maybe<int>.Nothing
                  select x + y;

          Console.WriteLine(r.HasValue ? r.Value.ToString() : "Nothing");

          r =     from x in 5.ToMaybe()
                  from y in 4.ToMaybe()
                  select x + y;
          Console.WriteLine(r.HasValue ? r.Value.ToString() : "Nothing");
          Console.WriteLine(
              from x in 1.ToMaybe()
              from y in 2.ToMaybe()
              from z in 3.ToMaybe()
              select x + y + z);

          Console.WriteLine(
              5.ToMaybe().SelectMany(x => Maybe<int>.Nothing,
                (x, y) => x + y));
          Console.WriteLine(
              5.ToMaybe().SelectMany(x => 4.ToMaybe(),
                (x, y) => x + y));
      }
  }

Expected output: no error message.

Actual output:

Exception caught by the compiler while compiling:
   Block that caused the problem begin at: monad2.cs(69,25):
                     Block being compiled: [monad2.cs(69,25):,Internal(1,1):]
System.Exception: Expression Mono.CSharp.ParameterReference did not set its
type after Resolve
called from: Mono.CSharp.ParameterReference
Exception caught by the compiler while compiling:
   Block that caused the problem begin at: monad2.cs(54,24):
                     Block being compiled: [monad2.cs(55,5):,monad2.cs(78,5):]
System.Exception: Expression Mono.CSharp.ParameterReference did not set its
type after Resolve
called from: Mono.CSharp.ParameterReference
Internal compiler error at monad2.cs(54,24):: exception caught while emitting
MethodBuilder [Test::Main]

Unhandled Exception: System.Exception: Expression
Mono.CSharp.ParameterReference did not set its type after Resolve
called from: Mono.CSharp.ParameterReference
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec, ResolveFlags
flags) [0x00000] 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.SimpleName.DoSimpleNameResolve (Mono.CSharp.EmitContext ec,
Mono.CSharp.Expression right_side, Boolean intermediate) [0x00000] 
  at Mono.CSharp.SimpleName.SimpleNameResolve (Mono.CSharp.EmitContext ec,
Mono.CSharp.Expression right_side, Boolean intermediate) [0x00000] 
  at Mono.CSharp.SimpleName.DoResolve (Mono.CSharp.EmitContext ec, Boolean
intermediate) [0x00000] 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec, ResolveFlags
flags) [0x00000] 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.Binary.DoResolve (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec, ResolveFlags
flags) [0x00000] 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.Return.DoResolve (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.ContextualReturn.DoResolve (Mono.CSharp.EmitContext ec)
[0x00000] 
  at Mono.CSharp.ExitStatement.Resolve (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.ExplicitBlock.Resolve (Mono.CSharp.EmitContext ec) [0x00000] 
  at Mono.CSharp.EmitContext.ResolveTopBlock (Mono.CSharp.EmitContext
anonymous_method_host, Mono.CSharp.ToplevelBlock block, Mono.CSharp.Parameters
ip, IMethodData md, System.Boolean& unreachable) [0x00000] 

If you "move" Maybe<T>.SelectMany into MaybeExtensions (making them extension
methods during this "move"), then the code compiles w/o error.

NET 3.5 CSC also compiles the code w/o error.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list