File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
ICSharpCode.Decompiler/IL/Transforms Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -716,13 +716,26 @@ internal static bool IsPotentialClosure(ITypeDefinition decompiledTypeDefinition
716716 return false ;
717717 }
718718
719- while ( potentialDisplayClass != decompiledTypeDefinition )
719+ // Make sure that potentialDisplayCLass and decompiledTypeDefinition are part of the same type tree
720+ // Either decompiledTypeDefinition is an ancestor type of potentialDisplayClass or both have
721+ // at least one common ancestor.
722+ var potentialDisplayClassAncestors = new HashSet < ITypeDefinition > ( ) ;
723+ var potentialDisplayClassParent = potentialDisplayClass . DeclaringTypeDefinition ;
724+ while ( potentialDisplayClassParent != null )
720725 {
721- potentialDisplayClass = potentialDisplayClass . DeclaringTypeDefinition ;
722- if ( potentialDisplayClass == null )
723- return false ;
726+ potentialDisplayClassAncestors . Add ( potentialDisplayClassParent ) ;
727+ potentialDisplayClassParent = potentialDisplayClassParent . DeclaringTypeDefinition ;
724728 }
725- return true ;
729+
730+ var decompiledTypeDefinitionOrAncestor = decompiledTypeDefinition ;
731+
732+ while ( decompiledTypeDefinitionOrAncestor != null )
733+ {
734+ if ( potentialDisplayClassAncestors . Contains ( decompiledTypeDefinitionOrAncestor ) )
735+ return true ;
736+ decompiledTypeDefinitionOrAncestor = decompiledTypeDefinitionOrAncestor . DeclaringTypeDefinition ;
737+ }
738+ return false ;
726739 }
727740
728741 readonly Stack < ILFunction > currentFunctions = new Stack < ILFunction > ( ) ;
You can’t perform that action at this time.
0 commit comments