diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index 4e3276c83..9c2be8cde 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -1125,7 +1125,7 @@ namespace ICSharpCode.Decompiler.Ast } } TypeCode code = TypeAnalysis.GetTypeCode(type); - if (code == TypeCode.Object) + if (code == TypeCode.Object || code == TypeCode.Empty) return new Ast.PrimitiveExpression((int)val); else return new Ast.PrimitiveExpression(CSharpPrimitiveCast.Cast(code, val, false)); diff --git a/ICSharpCode.Decompiler/ILAst/ILAstTypes.cs b/ICSharpCode.Decompiler/ILAst/ILAstTypes.cs index 89ad2b781..332690245 100644 --- a/ICSharpCode.Decompiler/ILAst/ILAstTypes.cs +++ b/ICSharpCode.Decompiler/ILAst/ILAstTypes.cs @@ -465,9 +465,12 @@ namespace ICSharpCode.Decompiler.ILAst public override void WriteTo(ITextOutput output) { - Debug.Assert(Values.Count > 0); - foreach (int i in this.Values) { - output.WriteLine("case {0}:", i); + if (this.Values != null) { + foreach (int i in this.Values) { + output.WriteLine("case {0}:", i); + } + } else { + output.WriteLine("default:"); } output.Indent(); base.WriteTo(output); diff --git a/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs b/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs index f29bdf3c4..9c211f83d 100644 --- a/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs +++ b/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs @@ -28,6 +28,10 @@ namespace ICSharpCode.Decompiler.ILAst ta.method = method; ta.InferTypes(method); ta.InferRemainingStores(); + // Now that stores were inferred, we can infer the remaining instructions that depended on those stored + // (but which didn't provide an expected type for the store) + // For example, this is necessary to make a switch() over a generated variable work correctly. + ta.InferTypes(method); } DecompilerContext context; @@ -356,7 +360,6 @@ namespace ICSharpCode.Decompiler.ILAst { ArrayType arrayType = InferTypeForExpression(expr.Arguments[0], null) as ArrayType; if (forceInferChildren) { - InferTypeForExpression(expr.Arguments[0], new ArrayType(typeSystem.Byte)); InferTypeForExpression(expr.Arguments[1], typeSystem.Int32); } return arrayType != null ? arrayType.ElementType : null;