Bug 43718 - mcs crashes when unable to resolve type inside lambda using the 'as' operator
Summary: mcs crashes when unable to resolve type inside lambda using the 'as' operator
Status: VERIFIED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 4.6.0 (C8)
Hardware: PC Mac OS
: --- normal
Target Milestone: 4.8.0 (C9)
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-08-24 19:38 UTC by Aaron Bockover [MSFT]
Modified: 2016-09-27 11:17 UTC (History)
4 users (show)

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

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:
VERIFIED FIXED

Description Aaron Bockover [MSFT] 2016-08-24 19:38:26 UTC
I am able to crash mcs:

  Mono JIT compiler version 4.6.0 (mono-4.6.0-branch/d0fc1a6 Tue Aug 16 10:27:45 EDT 2016)
  Mono C# compiler version 4.6.0.0

With the following sample:

  class Crashy {
    void Call (System.Action<object> action) { }
    public void DoCrash () => Call (f => f as Foo);
  }

The expectation is that not being able to resolve "Foo" (from within the lambda) should result in a diagnostic, not a hard crash. The "as" operator seems to be the culprit. Using a regular cast ((Foo)f) results in a diagnostic as expected.

Compiling the above:

  mcs crash.cs -t:library

Results in the following trace:

Unhandled Exception:
Mono.CSharp.InternalErrorException: crash.cs(7,14): Crashy.DoCrash() ---> Mono.CSharp.InternalErrorException: crash.cs(8,12): ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Mono.CSharp.TypeSpec.IsReferenceType (Mono.CSharp.TypeSpec t) [0x00000] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.As.DoResolve (Mono.CSharp.ResolveContext ec) [0x0002d] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.ResolveFlags flags) [0x0002a] in <65ad872b0e564119b94b07e7497063eb>:0 
   --- End of inner exception stack trace ---
  at Mono.CSharp.AnonymousMethodExpression.Compatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec type) [0x001b3] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.AnonymousMethodExpression.ImplicitStandardConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec delegate_type) [0x00037] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Convert.ImplicitConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression expr, Mono.CSharp.TypeSpec target_type) [0x0003e] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.OverloadResolver.IsArgumentCompatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.Argument argument, Mono.CSharp.Parameter+Modifier param_mod, Mono.CSharp.TypeSpec parameter) [0x000ca] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.OverloadResolver.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, System.Int32 arg_count, Mono.CSharp.MemberSpec& candidate, Mono.CSharp.IParametersMember pm, System.Boolean& params_expanded_form, System.Boolean& dynamicArgument, Mono.CSharp.TypeSpec& returnType, System.Boolean errorMode) [0x0072a] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.OverloadResolver.ResolveMember[T] (Mono.CSharp.ResolveContext rc, Mono.CSharp.Arguments& args) [0x0013b] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& args, Mono.CSharp.OverloadResolver+IErrorHandler cerrors, Mono.CSharp.OverloadResolver+Restrictions restr) [0x00064] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Invocation.DoResolveInvocation (Mono.CSharp.ResolveContext ec) [0x001d4] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext rc) [0x00007] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.ResolveFlags flags) [0x0002a] in <65ad872b0e564119b94b07e7497063eb>:0 
   --- End of inner exception stack trace ---
  at Mono.CSharp.Method.Emit () [0x00141] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.TypeDefinition.Emit () [0x0026e] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.ClassOrStruct.Emit () [0x00025] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Class.Emit () [0x00000] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.TypeDefinition.EmitContainer () [0x0000f] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x0001e] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00007] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x0001e] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.ModuleContainer.EmitContainer () [0x0009c] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.AssemblyDefinition.Emit () [0x00098] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.AssemblyDefinitionStatic.Emit () [0x00126] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Driver.Compile () [0x002f3] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00052] in <65ad872b0e564119b94b07e7497063eb>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: Mono.CSharp.InternalErrorException: crash.cs(7,14): Crashy.DoCrash() ---> Mono.CSharp.InternalErrorException: crash.cs(8,12): ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Mono.CSharp.TypeSpec.IsReferenceType (Mono.CSharp.TypeSpec t) [0x00000] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.As.DoResolve (Mono.CSharp.ResolveContext ec) [0x0002d] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.ResolveFlags flags) [0x0002a] in <65ad872b0e564119b94b07e7497063eb>:0 
   --- End of inner exception stack trace ---
  at Mono.CSharp.AnonymousMethodExpression.Compatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec type) [0x001b3] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.AnonymousMethodExpression.ImplicitStandardConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec delegate_type) [0x00037] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Convert.ImplicitConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression expr, Mono.CSharp.TypeSpec target_type) [0x0003e] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.OverloadResolver.IsArgumentCompatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.Argument argument, Mono.CSharp.Parameter+Modifier param_mod, Mono.CSharp.TypeSpec parameter) [0x000ca] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.OverloadResolver.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, System.Int32 arg_count, Mono.CSharp.MemberSpec& candidate, Mono.CSharp.IParametersMember pm, System.Boolean& params_expanded_form, System.Boolean& dynamicArgument, Mono.CSharp.TypeSpec& returnType, System.Boolean errorMode) [0x0072a] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.OverloadResolver.ResolveMember[T] (Mono.CSharp.ResolveContext rc, Mono.CSharp.Arguments& args) [0x0013b] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& args, Mono.CSharp.OverloadResolver+IErrorHandler cerrors, Mono.CSharp.OverloadResolver+Restrictions restr) [0x00064] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Invocation.DoResolveInvocation (Mono.CSharp.ResolveContext ec) [0x001d4] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext rc) [0x00007] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.ResolveFlags flags) [0x0002a] in <65ad872b0e564119b94b07e7497063eb>:0 
   --- End of inner exception stack trace ---
  at Mono.CSharp.Method.Emit () [0x00141] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.TypeDefinition.Emit () [0x0026e] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.ClassOrStruct.Emit () [0x00025] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Class.Emit () [0x00000] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.TypeDefinition.EmitContainer () [0x0000f] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x0001e] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00007] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x0001e] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.ModuleContainer.EmitContainer () [0x0009c] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.AssemblyDefinition.Emit () [0x00098] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.AssemblyDefinitionStatic.Emit () [0x00126] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Driver.Compile () [0x002f3] in <65ad872b0e564119b94b07e7497063eb>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00052] in <65ad872b0e564119b94b07e7497063eb>:0
Comment 1 Marek Safar 2016-08-25 16:46:24 UTC
Fixed in master and Mono 4.6