Browse Source

Fixed SD2-1469: Argument out of range exception in expression finder

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3714 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
abdf370ea4
  1. 2
      src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs
  2. 4
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs
  3. 26
      src/Libraries/NRefactory/Test/Lexer/CSharp/LexerPositionTests.cs
  4. 14
      src/Main/Base/Test/CSharpExpressionFinderTests.cs

2
src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs

@ -226,7 +226,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -226,7 +226,7 @@ namespace ICSharpCode.NRefactory.Parser
return 0;
}
protected bool WasLineEnd(char ch)
bool WasLineEnd(char ch)
{
// Handle MS-DOS or MacOS line ends.
if (ch == '\r') {

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

@ -576,8 +576,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -576,8 +576,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
int x = Col - 1;
int y = Line;
int nextChar = ReaderRead();
if (nextChar == -1) {
errors.Error(y, x, String.Format("End of file reached inside character literal"));
if (nextChar == -1 || HandleLineEnd((char)nextChar)) {
errors.Error(y, x, String.Format("End of line reached inside character literal"));
return null;
}
char ch = (char)nextChar;

26
src/Libraries/NRefactory/Test/Lexer/CSharp/LexerPositionTests.cs

@ -29,6 +29,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -29,6 +29,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
Token t = l.NextToken();
Assert.AreEqual(new Location(1, 1), t.Location);
}
[Test]
public void Test2()
{
@ -37,6 +38,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -37,6 +38,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(8, 1), t.Location);
}
[Test]
public void TestReturn()
{
@ -45,6 +47,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -45,6 +47,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(1, 2), t.Location);
}
[Test]
public void TestSpace()
{
@ -52,6 +55,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -52,6 +55,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
Token t = l.NextToken();
Assert.AreEqual(new Location(3, 1), t.Location);
}
[Test]
public void TestOctNumber()
{
@ -59,6 +63,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -59,6 +63,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
Token t = l.NextToken();
Assert.AreEqual(new Location(1, 1), t.Location);
}
[Test]
public void TestHexNumber()
{
@ -68,6 +73,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -68,6 +73,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(7, 1), t.Location);
}
[Test]
public void TestHexNumberChar()
{
@ -77,6 +83,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -77,6 +83,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(9, 1), t.Location);
}
[Test]
public void TestFloationPointNumber()
{
@ -86,6 +93,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -86,6 +93,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(7, 1), t.Location);
}
[Test]
public void TestVerbatimString()
{
@ -95,6 +103,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -95,6 +103,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(9, 1), t.Location);
}
[Test]
public void TestAtIdent()
{
@ -104,6 +113,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -104,6 +113,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(9, 1), t.Location);
}
[Test]
public void TestNoFloationPointNumber()
{
@ -115,6 +125,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -115,6 +125,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(3, 1), t.Location);
}
[Test]
public void TestNumber()
{
@ -123,6 +134,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -123,6 +134,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(1, 2), t.Location);
}
[Test]
public void TestNumber2()
{
@ -131,6 +143,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -131,6 +143,7 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken();
Assert.AreEqual(new Location(4, 1), t.Location);
}
[Test]
public void TestOperator()
{
@ -139,5 +152,18 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp @@ -139,5 +152,18 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
Assert.AreEqual(new Location(1, 1), t.Location);
Assert.AreEqual(Tokens.EOF, l.NextToken().kind);
}
[Test]
public void TestPositionLineBreakAfterApostrophe()
{
// see SD2-1469
// the expression finder requires correct positions even when there are syntax errors
ILexer l = GenerateLexer("'\r\nvoid");
Token t = l.NextToken();
// the incomplete char literal should not generate a token
Assert.AreEqual(Tokens.Void, t.kind);
Assert.AreEqual(new Location(1, 2), t.Location);
Assert.AreEqual(Tokens.EOF, l.NextToken().kind);
}
}
}

14
src/Main/Base/Test/CSharpExpressionFinderTests.cs

@ -1147,6 +1147,20 @@ class Main { @@ -1147,6 +1147,20 @@ class Main {
Assert.AreEqual("System", result.Expression);
Assert.AreEqual(ExpressionContext.Namespace, result.Context);
}
[Test]
public void SD2_1469()
{
// Test that this doesn't crash
const string program = @"class MainWindow
{
'
void MainWindowDeleteEvent()
{
}
}";
ef.FindFullExpression(program, 25);
}
}
}

Loading…
Cancel
Save