Skip to content

Unable to parse expression bodies #43

Description

@luvies

I've found that it is unable to parse expression bodied like

float GetThrusterOverridePercent(List<IMyThrust> thrusters) => thrusters[0].ThrustOverridePercentage;

if you convert to block bodies

 float GetThrusterOverridePercent(List<IMyThrust> thrusters) { return thrusters[0].ThrustOverridePercentage; }

then it seems to compile just fine. So far, I've found this on both property and function expression bodies.

Edit: I forgot to add some actually useful info for nailing this bug down, so here it is. The property expression bodies and function expression bodies seem to throw different errors, so I'm not sure what the issue might be.

Property error:

System.ArgumentException
  HResult=0x80070057
  Message=An item with the same key has already been added.
  Source=mscorlib
  StackTrace:
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at CSharpMinifier.MinifyLocalsAstVisitor.VisitMember(String memberName, IEnumerable`1 parameters) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\MinifyLocalsAstVisitor.cs:line 114
   at CSharpMinifier.MinifyLocalsAstVisitor.VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\MinifyLocalsAstVisitor.cs:line 86
   at ICSharpCode.NRefactory.CSharp.ConstructorDeclaration.AcceptVisitor(IAstVisitor visitor)
   at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitChildren(AstNode node)
   at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration)
   at CSharpMinifier.MinifyLocalsAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\MinifyLocalsAstVisitor.cs:line 44
   at ICSharpCode.NRefactory.CSharp.TypeDeclaration.AcceptVisitor(IAstVisitor visitor)
   at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitChildren(AstNode node)
   at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
   at CSharpMinifier.MinifyLocalsAstVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\MinifyLocalsAstVisitor.cs:line 38
   at ICSharpCode.NRefactory.CSharp.NamespaceDeclaration.AcceptVisitor(IAstVisitor visitor)
   at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitChildren(AstNode node)
   at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitSyntaxTree(SyntaxTree syntaxTree)
   at ICSharpCode.NRefactory.CSharp.SyntaxTree.AcceptVisitor(IAstVisitor visitor)
   at CSharpMinifier.Minifier.CompileAndAcceptVisitor(DepthFirstAstVisitor visitor) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\Minifier.cs:line 496
   at CSharpMinifier.Minifier.CompressLocals() in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\Minifier.cs:line 401
   at CSharpMinifier.Minifier.Minify() in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\Minifier.cs:line 136
   at CSharpMinifier.Minifier.MinifyFromString(String csharpCode) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\Minifier.cs:line 127
   at CSharpMinifier.GUI.frmMain.btnMinify_Click(Object sender, EventArgs e) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier.GUI\frmMain.cs:line 126
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at CSharpMinifier.GUI.Program.Main() in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier.GUI\Program.cs:line 16

Function error:

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type 'ICSharpCode.NRefactory.CSharp.ErrorNode' to type 'ICSharpCode.NRefactory.CSharp.CSharpTokenNode'.
  Source=CSharpMinifier
  StackTrace:
   at CSharpMinifier.MinifyMembersAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\MinifyMembersAstVisitor.cs:line 80
   at ICSharpCode.NRefactory.CSharp.TypeDeclaration.AcceptVisitor(IAstVisitor visitor)
   at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitChildren(AstNode node)
   at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitSyntaxTree(SyntaxTree syntaxTree)
   at ICSharpCode.NRefactory.CSharp.SyntaxTree.AcceptVisitor(IAstVisitor visitor)
   at CSharpMinifier.Minifier.CompileAndAcceptVisitor(DepthFirstAstVisitor visitor) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\Minifier.cs:line 496
   at CSharpMinifier.Minifier.CompressMembers() in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\Minifier.cs:line 423
   at CSharpMinifier.Minifier.Minify() in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\Minifier.cs:line 138
   at CSharpMinifier.Minifier.MinifyFromString(String csharpCode) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier\Minifier.cs:line 127
   at CSharpMinifier.GUI.frmMain.btnMinify_Click(Object sender, EventArgs e) in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier.GUI\frmMain.cs:line 126
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at CSharpMinifier.GUI.Program.Main() in C:\Users\luke\Documents\Development\External\CSharp-Minifier\CSharpMinifier.GUI\Program.cs:line 16

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions