diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/TrickyTypes.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/TrickyTypes.cs index ffbbef707..734a309c9 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/TrickyTypes.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/TrickyTypes.cs @@ -30,6 +30,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness StringConcat(); LinqNullableMin(); LinqNullableMin(1, 2, 3); + UnboxingToWrongType(); } static void Print(T val) @@ -110,5 +111,49 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness Print(string.Format("LinqNullableMin {0}:", arr.Length)); Print(arr.Min(v => (int?)v)); } + + static void UnboxingToWrongType() + { + Console.WriteLine("UnboxingToWrongType:"); + object o = 3.50; + try + { + Print((long)o); + } + catch (Exception ex) + { + Console.WriteLine(ex.GetType().Name + ": " + ex.Message); + } + try + { + Print(o as long?); + } + catch (Exception ex) + { + Console.WriteLine(ex.GetType().Name + ": " + ex.Message); + } + try + { + Print((long)(o as long?)); + } + catch (Exception ex) + { + Console.WriteLine(ex.GetType().Name + ": " + ex.Message); + } + try + { + Print((long)(o is long ? o : null)); + } + catch (Exception ex) + { + Console.WriteLine(ex.GetType().Name + ": " + ex.Message); + } +#if CS90 + if (o is not 0L) + { + Console.WriteLine("Not 0L"); + } +#endif + } } }