Browse Source

Fixed null reference exception that occurs when a Python method is missing its last parameter.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3001 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
6722800a0e
  1. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonAstWalker.cs
  2. 42
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/MissingLastParameterFromMethodTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

6
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonAstWalker.cs

@ -180,8 +180,10 @@ namespace ICSharpCode.PythonBinding @@ -180,8 +180,10 @@ namespace ICSharpCode.PythonBinding
// Ignore first parameter since this is the "self" parameter.
for (int i = 1; i < expressions.Count; ++i) {
NameExpression expression = expressions[i] as NameExpression;
DefaultParameter parameter = new DefaultParameter(expression.Name.ToString(), null, new DomRegion());
parameters.Add(parameter);
if (expression != null) {
DefaultParameter parameter = new DefaultParameter(expression.Name.ToString(), null, new DomRegion());
parameters.Add(parameter);
}
}
return parameters.ToArray();
}

42
src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/MissingLastParameterFromMethodTestFixture.cs

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop.Dom;
using NUnit.Framework;
using PythonBinding.Tests;
namespace PythonBinding.Tests.Parsing
{
/// <summary>
/// Tests that the python parser does not throw an exception
/// when the last parameter is missing from a method.
/// </summary>
[TestFixture]
public class MissingLastParameterFromMethodTestFixture
{
ICompilationUnit compilationUnit;
[TestFixtureSetUp]
public void SetUpFixture()
{
string python = "class Class1:\r\n" +
" def method(arg1,arg2,";
DefaultProjectContent projectContent = new DefaultProjectContent();
PythonParser parser = new PythonParser();
compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);
}
[Test]
public void CompilationUnitIsNotNull()
{
Assert.IsNotNull(compilationUnit);
}
}
}

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -130,6 +130,7 @@ @@ -130,6 +130,7 @@
<Compile Include="Parsing\ClassWithBaseClassTestFixture.cs" />
<Compile Include="Parsing\IronPythonParserTestFixture.cs" />
<Compile Include="Parsing\MethodWithParametersTestFixture.cs" />
<Compile Include="Parsing\MissingLastParameterFromMethodTestFixture.cs" />
<Compile Include="Parsing\ParseClassWithCtorTestFixture.cs" />
<Compile Include="Parsing\ParseClassWithMethodTestFixture.cs" />
<Compile Include="Parsing\ParseImportTestFixture.cs" />

Loading…
Cancel
Save