Browse Source

Fixed SD2-1202: NullReferenceException for incomplete type argument list

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2048 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
c7e62da426
  1. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  2. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  3. 35
      src/Libraries/NRefactory/Test/Parser/Expressions/ObjectCreateExpressionTests.cs

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

@ -4723,7 +4723,7 @@ canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma)) { @@ -4723,7 +4723,7 @@ canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma)) {
out type);
#line 2007 "cs.ATG"
types.Add(type);
if (type != null) { types.Add(type); }
while (la.kind == 14) {
lexer.NextToken();
Type(
@ -4731,7 +4731,7 @@ out type); @@ -4731,7 +4731,7 @@ out type);
out type);
#line 2008 "cs.ATG"
types.Add(type);
if (type != null) { types.Add(type); }
}
} else SynErr(185);
Expect(22);

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -2004,8 +2004,8 @@ TypeArgumentList<out List<TypeReference> types, bool canBeUnbound> @@ -2004,8 +2004,8 @@ TypeArgumentList<out List<TypeReference> types, bool canBeUnbound>
( IF (canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma))
(. types.Add(TypeReference.Null); .)
{ "," (. types.Add(TypeReference.Null); .) }
| Type<out type> (. types.Add(type); .)
{ "," Type<out type> (. types.Add(type); .) }
| Type<out type> (. if (type != null) { types.Add(type); } .)
{ "," Type<out type> (. if (type != null) { types.Add(type); } .) }
)
">"
.

35
src/Libraries/NRefactory/Test/Parser/Expressions/ObjectCreateExpressionTests.cs

@ -47,6 +47,23 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -47,6 +47,23 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsTrue(expr.Arguments[0] is ObjectCreateExpression);
CheckSimpleObjectCreateExpression((ObjectCreateExpression)expr.Arguments[0]);
}
[Test]
public void CSharpInvalidTypeArgumentListObjectCreateExpressionTest()
{
// this test was written because this bug caused the AbstractASTVisitor to crash
InvocationExpression expr = ParseUtilCSharp.ParseExpression<InvocationExpression>("WriteLine(new SomeGenericType<int, >())", true);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("WriteLine", ((IdentifierExpression)expr.TargetObject).Identifier);
Assert.AreEqual(1, expr.Arguments.Count); // here a second null parameter was added incorrectly
Assert.IsTrue(expr.Arguments[0] is ObjectCreateExpression);
TypeReference typeRef = ((ObjectCreateExpression)expr.Arguments[0]).CreateType;
Assert.AreEqual("SomeGenericType", typeRef.Type);
Assert.AreEqual(1, typeRef.GenericTypes.Count);
Assert.AreEqual("int", typeRef.GenericTypes[0].Type);
}
#endregion
#region VB.NET
@ -55,7 +72,23 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -55,7 +72,23 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
CheckSimpleObjectCreateExpression(ParseUtilVBNet.ParseExpression<ObjectCreateExpression>("New MyObject(1, 2, 3)"));
}
[Test]
public void VBNetInvalidTypeArgumentListObjectCreateExpressionTest()
{
// this test was written because this bug caused the AbstractASTVisitor to crash
InvocationExpression expr = ParseUtilVBNet.ParseExpression<InvocationExpression>("WriteLine(New SomeGenericType(Of Integer, )())", true);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("WriteLine", ((IdentifierExpression)expr.TargetObject).Identifier);
Assert.AreEqual(1, expr.Arguments.Count); // here a second null parameter was added incorrectly
Assert.IsTrue(expr.Arguments[0] is ObjectCreateExpression);
TypeReference typeRef = ((ObjectCreateExpression)expr.Arguments[0]).CreateType;
Assert.AreEqual("SomeGenericType", typeRef.Type);
Assert.AreEqual(1, typeRef.GenericTypes.Count);
Assert.AreEqual("Integer", typeRef.GenericTypes[0].Type);
}
#endregion
}
}

Loading…
Cancel
Save