Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Fix crash in ConvertToInitializer context action.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Jan 9, 2013
1 parent 9acb174 commit 6c62a05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ bool TryHandleInitializer(AstNode node)
return false;
}
variableInitializer = variableDeclarationStatement.Variables.FirstOrNullObject();
if (variableInitializer.IsNull)
if (variableInitializer.IsNull || variableInitializer.Initializer.IsNull)
return false;
var sourceResolveResult = context.Resolve(variableInitializer.Initializer) as LocalResolveResult;
if (HasDependency(variableInitializer.Initializer) && !CanReplaceDependent(sourceResolveResult))
return false;
var targetResolveResult = context.Resolve(variableInitializer) as LocalResolveResult;
if (targetResolveResult == null)
return false;
AddNewVariable(targetResolveResult.Variable, variableInitializer.Initializer, node);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,20 @@ void F()
// And another statement to make the converter even try
s = """";
}
}");
}

[Test]
public void DoesNotCrashOnVariableDeclarationWithoutInitializer()
{
TestWrongContext<ConvertToInitializerAction>(@"
class TestClass
{
void F()
{
TestClass $s1 = new TestClass();
TestClass s2;
}
}");
}
}
Expand Down

0 comments on commit 6c62a05

Please sign in to comment.