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

Commit

Permalink
Fix bug in IronPython local variable resolver getting the wrong type …
Browse files Browse the repository at this point in the history
…due to an off by one problem with line numbers and a problem with name resolution when variable used in several statements.
  • Loading branch information
mrward committed Sep 25, 2010
1 parent 9fcf7b1 commit 1b445fa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Expand Up @@ -86,6 +86,8 @@ public override bool Walk(CallExpression node)
{
if (foundVariableAssignment) {
typeName = GetTypeName(node.Target);
currentAssignStatement = null;
foundVariableAssignment = false;
}
return base.Walk(node);
}
Expand Down
Expand Up @@ -81,9 +81,9 @@ public void Resolve_LocalVariableIsReDefinedAfterLineBeingConsidered_ResolveResu

ExpressionResult expression = new ExpressionResult("a");
expression.Region = new DomRegion(
beginLine: 1,
beginLine: 2,
beginColumn: 0,
endLine: 1,
endLine: 2,
endColumn: 1);

resolverHelper.Resolve(expression, python);
Expand All @@ -106,7 +106,7 @@ public void Resolve_LocalVariableIsReDefinedAfterLineBeingConsideredAndExpressio

ExpressionResult expression = new ExpressionResult("a");
expression.Region = new DomRegion(
beginLine: 1,
beginLine: 2,
beginColumn: 0,
endLine: -1,
endColumn: 1);
Expand Down Expand Up @@ -140,5 +140,41 @@ public void Resolve_LocalVariableTypeIsImported_ResolveResultResolvedTypeDetermi

Assert.AreEqual(myClass, underlyingClass);
}

[Test]
public void Resolve_LocalVariableMethodIsCalledOnPreviousLine_ResolveResultResolvedTypeIsTestClass()
{
CreateResolver();

string python =
"a = Test.Test1()\r\n" +
"a.foo()\r\n" +
"a";

resolverHelper.Resolve("a", python);

IReturnType resolvedType = resolverHelper.LocalResolveResult.ResolvedType;
IClass underlyingClass = resolvedType.GetUnderlyingClass();

Assert.AreEqual(testClass, underlyingClass);
}

[Test]
public void Resolve_LocalVariableMethodIsCalledAfterVariableOnItsOwnOnPreviousLine_ResolveResultResolvedTypeIsTestClass()
{
CreateResolver();

string python =
"a = Test.Test1()\r\n" +
"a\r\n" +
"a.foo()\r\n";

resolverHelper.Resolve("a", python);

IReturnType resolvedType = resolverHelper.LocalResolveResult.ResolvedType;
IClass underlyingClass = resolvedType.GetUnderlyingClass();

Assert.AreEqual(testClass, underlyingClass);
}
}
}
Expand Up @@ -19,6 +19,9 @@ public ScriptingLocalMethod(string code)
}
}

/// <summary>
/// End line is one based.
/// </summary>
public string GetCode(int endLine)
{
int endIndex = FindIndexForEndOfLine(endLine);
Expand All @@ -31,7 +34,7 @@ public string GetCode(int endLine)
int FindIndexForEndOfLine(int line)
{
int index = 0;
for (int i = 0; i <= line; ++i) {
for (int i = 0; i < line; ++i) {
index = code.IndexOf('\n', index) + 1;
}
return index;
Expand Down

0 comments on commit 1b445fa

Please sign in to comment.