Skip to content

Commit

Permalink
Add a fix for when type.Scope is null
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Aug 30, 2012
1 parent 26e4aa4 commit 13a5fd8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion AssemblyData/methodsrewriter/ResolverUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static bool compareTypeReferences(Type a, TypeReference b) {

var asmRef = DotNetUtils.getAssemblyNameReference(b);
var asmName = a.Assembly.GetName();
if (asmRef.Name != asmName.Name)
if (asmRef == null || asmRef.Name != asmName.Name)
return false;

return compareTypes(a.DeclaringType, b.DeclaringType);
Expand Down
5 changes: 4 additions & 1 deletion blocks/DotNetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,9 @@ static void calculateStackUsage_nonCall(Instruction instr, bool methodHasReturnV

public static AssemblyNameReference getAssemblyNameReference(TypeReference type) {
var scope = type.Scope;
if (scope == null)
return null;

if (scope is ModuleDefinition) {
var moduleDefinition = (ModuleDefinition)scope;
return moduleDefinition.Assembly.Name;
Expand All @@ -946,7 +949,7 @@ public static AssemblyNameReference getAssemblyNameReference(TypeReference type)

public static string getFullAssemblyName(TypeReference type) {
var asmRef = getAssemblyNameReference(type);
return asmRef.FullName;
return asmRef == null ? null : asmRef.FullName;
}

public static bool isAssembly(IMetadataScope scope, string assemblySimpleName) {
Expand Down
2 changes: 2 additions & 0 deletions de4dot.code/ExternalAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ExternalAssemblies {

ExternalAssembly load(TypeReference type) {
var asmFullName = DotNetUtils.getFullAssemblyName(type);
if (asmFullName == null)
return null;
ExternalAssembly asm;
if (assemblies.TryGetValue(asmFullName, out asm))
return asm;
Expand Down
2 changes: 2 additions & 0 deletions de4dot.code/renamer/asmmodules/Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ public void cleanUp() {
// Returns null if it's a non-loaded module/assembly
IEnumerable<Module> findModules(TypeReference type) {
var scope = type.Scope;
if (scope == null)
return null;

if (scope is AssemblyNameReference)
return findModules((AssemblyNameReference)scope);
Expand Down

0 comments on commit 13a5fd8

Please sign in to comment.