Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion: Named arguments do not use correct type for thisVarType #2582

Closed
greenozon opened this issue Dec 18, 2021 · 2 comments
Closed

Assertion: Named arguments do not use correct type for thisVarType #2582

greenozon opened this issue Dec 18, 2021 · 2 comments
Labels
Bug Decompiler The decompiler engine itself

Comments

@greenozon
Copy link

Input code

Save code
assembly is not obfuscated

Erroneous output

Error decompiling @060001A8 Unity.Injection.InjectionFactory.AddPolicies
in assembly "C:\Temp\err120.dll"
 ---> ICSharpCode.ILSpy.AssertionFailedException: 
   at ICSharpCode.ILSpy.ILSpyTraceListener.Fail(String message, String detailMessage) in offset 380
   at ICSharpCode.ILSpy.ILSpyTraceListener.Fail(String message) in offset 9
   at System.Diagnostics.TraceInternal.Fail(String message) in offset 55
   at System.Diagnostics.Debug.Assert(Boolean condition) in offset 6
   at ICSharpCode.Decompiler.IL.StLoc.CheckInvariant(ILPhase phase) in StLoc.cs:line 44
   at ICSharpCode.Decompiler.IL.ILInstruction.CheckInvariant(ILPhase phase) in ILInstruction.cs:line 95
   at ICSharpCode.Decompiler.IL.Block.CheckInvariant(ILPhase phase) in Block.cs:line 108
   at ICSharpCode.Decompiler.IL.Transforms.StatementTransform.Run(Block block, BlockTransformContext context) in StatementTransform.cs:line 138
   at ICSharpCode.Decompiler.IL.Block.RunTransforms(IEnumerable`1 transforms, BlockTransformContext context) in Block.cs:line 318
   at ICSharpCode.Decompiler.IL.Transforms.BlockILTransform.VisitBlock(ControlFlowNode cfgNode, BlockTransformContext context) in BlockTransform.cs:line 118
   at ICSharpCode.Decompiler.IL.Transforms.BlockILTransform.Run(ILFunction function, ILTransformContext context) in BlockTransform.cs:line 90
   at ICSharpCode.Decompiler.IL.ILFunction.RunTransforms(IEnumerable`1 transforms, ILTransformContext context) in ILFunction.cs:line 405
   at ICSharpCode.Decompiler.IL.Transforms.DelegateConstruction.TransformDelegateConstruction(ILInstruction value, IMethod targetMethod, ILInstruction target, IType delegateType) in DelegateConstruction.cs:line 207
   at ICSharpCode.Decompiler.IL.Transforms.DelegateConstruction.ICSharpCode.Decompiler.IL.Transforms.IILTransform.Run(ILFunction function, ILTransformContext context) in DelegateConstruction.cs:line 56
   at ICSharpCode.Decompiler.IL.ILFunction.RunTransforms(IEnumerable`1 transforms, ILTransformContext context) in ILFunction.cs:line 405
   at ICSharpCode.Decompiler.IL.Transforms.LocalFunctionDecompiler.ReadLocalFunctionDefinition(ILFunction rootFunction, IMethod targetMethod, Int32 skipCount) in LocalFunctionDecompiler.cs:line 479
   at ICSharpCode.Decompiler.IL.Transforms.LocalFunctionDecompiler.<FindUseSites>g__HandleUseSite|12_0(IMethod targetMethod, ILInstruction inst, <>c__DisplayClass12_0&) in LocalFunctionDecompiler.cs:line 433
   at ICSharpCode.Decompiler.IL.Transforms.LocalFunctionDecompiler.FindUseSites(ILFunction function, ILTransformContext context, Dictionary`2 localFunctions) in LocalFunctionDecompiler.cs:line 410
   at ICSharpCode.Decompiler.IL.Transforms.LocalFunctionDecompiler.Run(ILFunction function, ILTransformContext context) in LocalFunctionDecompiler.cs:line 95
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1551
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1588
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1465
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1318
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompileTypes(IEnumerable`1 types, DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) in CSharpDecompiler.cs:line 574
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileTypes(IEnumerable`1 types) in CSharpDecompiler.cs:line 894
   at ICSharpCode.Decompiler.CSharp.ProjectDecompiler.WholeProjectDecompiler.<>c__DisplayClass45_0.<WriteCodeFilesInProject>b__2(IGrouping`2 file) in WholeProjectDecompiler.cs:line 239
   at System.Threading.Tasks.Parallel.<>c__DisplayClass42_0`2.<PartitionerForEachWorker>b__1() in offset 713
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) in offset 6
   at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object <p0>) in offset 134

Details

ILSpy version 7.2.0.6792-preview4
.NET version 4.8.3928.0
err120.zip

@greenozon greenozon added Bug Decompiler The decompiler engine itself labels Dec 18, 2021
@siegfriedpammer
Copy link
Member

Looks like the NamedArgumentTransform uses the wrong type for the this argument. It defaults to the declaring type of the invoked method, however in this case this causes conflicts with T&.

Adding

IType thisVarType = call.Arguments[0].InferType(context.TypeSystem);
if (thisVarType.Kind == TypeKind.Unknown)
{
	thisVarType = call.Method.DeclaringType;
}

at https://github.com/icsharpcode/ILSpy/blob/master/ICSharpCode.Decompiler/IL/Transforms/NamedArgumentTransform.cs#L101 would be my proposed fix. @dgrunwald what do you think? Am I missing something?

@dgrunwald
Copy link
Member

dgrunwald commented Dec 18, 2021

InferType doesn't seem appropriate to me in that context.
And at best it would make the assertion less likely, without actually fixing it in all cases.

@siegfriedpammer siegfriedpammer changed the title Assert at ICSharpCode.Decompiler.IL.StLoc.CheckInvariant Assertion: Named arguments do not use correct type for thisVarType Dec 26, 2021
dgrunwald added a commit that referenced this issue Apr 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

3 participants