Bug 20493

Summary: Mono.CSharp.InternalErrorException when event with extension method is accessed in lambda from child class
Product: [Mono] Compilers Reporter: Darrel <darrel.liu>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 3.4.0   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Darrel 2014-06-09 18:38:55 UTC
Compile this, and the compiler crashes instead of giving meaningful error message.

using System;
using System.Linq;

public static class EventExtensions
{
    public static void Raise(this EventHandler h, object s, EventArgs e) {
        if (h != null) h(s, e);
    }
}

public class Parent
{
    public event EventHandler evt;
}

public class Child : Parent
{
    public void Run() {
        (new string[0] { }).ToList().ForEach(s => evt.Raise(this, EventArgs.Empty));
    }
}

% /Library/Frameworks/Mono.framework/Versions/3.4.0/bin/mcs Crash.cs

Unhandled Exception:
Mono.CSharp.InternalErrorException: ./Crash.cs(18,17): Child.Run() ---> Mono.CSharp.InternalErrorException: ./Crash.cs(19,46): ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Mono.CSharp.MemberAccess.LookupNameExpression (Mono.CSharp.ResolveContext rc, MemberLookupRestrictions restrictions) [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 
  --- End of inner exception stack trace ---
  at Mono.CSharp.AnonymousMethodExpression.Compatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec type) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AnonymousMethodExpression.ImplicitStandardConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec delegate_type) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Convert.ImplicitConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression expr, Mono.CSharp.TypeSpec target_type) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.OverloadResolver.IsArgumentCompatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.Argument argument, Modifier param_mod, Mono.CSharp.TypeSpec parameter) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.OverloadResolver.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, Mono.CSharp.MemberSpec& candidate, IParametersMember pm, System.Boolean& params_expanded_form, System.Boolean& dynamicArgument, Mono.CSharp.TypeSpec& returnType) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.OverloadResolver.ResolveMember[MethodSpec] (Mono.CSharp.ResolveContext rc, Mono.CSharp.Arguments& args) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& args, IErrorHandler cerrors, Restrictions restr) [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 
  --- End of inner exception stack trace ---
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeDefinition.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ClassOrStruct.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Class.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeDefinition.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ModuleContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AssemblyDefinition.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AssemblyDefinitionStatic.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: Mono.CSharp.InternalErrorException: ./Crash.cs(18,17): Child.Run() ---> Mono.CSharp.InternalErrorException: ./Crash.cs(19,46): ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Mono.CSharp.MemberAccess.LookupNameExpression (Mono.CSharp.ResolveContext rc, MemberLookupRestrictions restrictions) [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 
  --- End of inner exception stack trace ---
  at Mono.CSharp.AnonymousMethodExpression.Compatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec type) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AnonymousMethodExpression.ImplicitStandardConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec delegate_type) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Convert.ImplicitConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression expr, Mono.CSharp.TypeSpec target_type) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.OverloadResolver.IsArgumentCompatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.Argument argument, Modifier param_mod, Mono.CSharp.TypeSpec parameter) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.OverloadResolver.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, Mono.CSharp.MemberSpec& candidate, IParametersMember pm, System.Boolean& params_expanded_form, System.Boolean& dynamicArgument, Mono.CSharp.TypeSpec& returnType) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.OverloadResolver.ResolveMember[MethodSpec] (Mono.CSharp.ResolveContext rc, Mono.CSharp.Arguments& args) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& args, IErrorHandler cerrors, Restrictions restr) [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 
  --- End of inner exception stack trace ---
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeDefinition.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ClassOrStruct.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Class.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeDefinition.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ModuleContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AssemblyDefinition.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AssemblyDefinitionStatic.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
Comment 1 Marek Safar 2014-06-11 08:26:35 UTC
Fixed in master