Browse Source

Fix bug in IronPython local variable resolver getting the wrong type due to an off by one problem with line numbers and a problem with name resolution when variable used in several statements.

pull/1/head
mrward 15 years ago
parent
commit
1b445fa671
  1. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonLocalVariableResolver.cs
  2. 42
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveLocalClassInstanceTests.cs
  3. 5
      src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingLocalMethod.cs

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonLocalVariableResolver.cs

@ -86,6 +86,8 @@ namespace ICSharpCode.PythonBinding @@ -86,6 +86,8 @@ namespace ICSharpCode.PythonBinding
{
if (foundVariableAssignment) {
typeName = GetTypeName(node.Target);
currentAssignStatement = null;
foundVariableAssignment = false;
}
return base.Walk(node);
}

42
src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveLocalClassInstanceTests.cs

@ -81,9 +81,9 @@ namespace PythonBinding.Tests.Resolver @@ -81,9 +81,9 @@ namespace PythonBinding.Tests.Resolver
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);
@ -106,7 +106,7 @@ namespace PythonBinding.Tests.Resolver @@ -106,7 +106,7 @@ namespace PythonBinding.Tests.Resolver
ExpressionResult expression = new ExpressionResult("a");
expression.Region = new DomRegion(
beginLine: 1,
beginLine: 2,
beginColumn: 0,
endLine: -1,
endColumn: 1);
@ -140,5 +140,41 @@ namespace PythonBinding.Tests.Resolver @@ -140,5 +140,41 @@ namespace PythonBinding.Tests.Resolver
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);
}
}
}

5
src/AddIns/BackendBindings/Scripting/Project/Src/ScriptingLocalMethod.cs

@ -19,6 +19,9 @@ namespace ICSharpCode.Scripting @@ -19,6 +19,9 @@ namespace ICSharpCode.Scripting
}
}
/// <summary>
/// End line is one based.
/// </summary>
public string GetCode(int endLine)
{
int endIndex = FindIndexForEndOfLine(endLine);
@ -31,7 +34,7 @@ namespace ICSharpCode.Scripting @@ -31,7 +34,7 @@ namespace ICSharpCode.Scripting
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;

Loading…
Cancel
Save