diff --git a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs index 4551eda142..0ed576a463 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs @@ -1854,18 +1854,17 @@ out implementsClause); } case 2: case 45: case 49: case 51: case 52: case 53: case 54: case 57: case 74: case 91: case 94: case 103: case 108: case 113: case 120: case 126: case 130: case 133: case 156: case 162: case 169: case 188: case 197: case 198: case 208: case 209: case 215: { -#line 1026 "VBNET.ATG" - Location startPos = t.Location; - -#line 1028 "VBNET.ATG" +#line 1027 "VBNET.ATG" m.Check(Modifiers.Fields); FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier); - fd.StartLocation = m.GetDeclarationLocation(startPos); IdentifierForFieldDeclaration(); -#line 1032 "VBNET.ATG" +#line 1030 "VBNET.ATG" string name = t.val; + +#line 1031 "VBNET.ATG" + fd.StartLocation = m.GetDeclarationLocation(t.Location); VariableDeclaratorPartAfterIdentifier( #line 1033 "VBNET.ATG" variableDeclarators, name); diff --git a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG index 1392e53695..c7900d8ac0 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG +++ b/src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG @@ -1023,13 +1023,13 @@ StructureMemberDecl attributes> .) EndOfStmt | /* 9.6 */ - (. Location startPos = t.Location; .) (. m.Check(Modifiers.Fields); FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier); - fd.StartLocation = m.GetDeclarationLocation(startPos); .) IdentifierForFieldDeclaration (. string name = t.val; .) + (. fd.StartLocation = m.GetDeclarationLocation(t.Location); .) + VariableDeclaratorPartAfterIdentifier { "," VariableDeclarator } EndOfStmt diff --git a/src/Libraries/NRefactory/Test/NRefactoryTests.csproj b/src/Libraries/NRefactory/Test/NRefactoryTests.csproj index cd460a9d29..ed42c526ec 100644 --- a/src/Libraries/NRefactory/Test/NRefactoryTests.csproj +++ b/src/Libraries/NRefactory/Test/NRefactoryTests.csproj @@ -80,6 +80,7 @@ + diff --git a/src/Libraries/NRefactory/Test/Parser/SnippetParserTests.cs b/src/Libraries/NRefactory/Test/Parser/SnippetParserTests.cs new file mode 100644 index 0000000000..9b91db99b4 --- /dev/null +++ b/src/Libraries/NRefactory/Test/Parser/SnippetParserTests.cs @@ -0,0 +1,26 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.NRefactory.Ast; +using System; +using NUnit.Framework; + +namespace ICSharpCode.NRefactory.Tests +{ + [TestFixture] + public class SnippetParserTests + { + [Test] + public void InvalidExpressionSyntax() + { + // SD2-1584: ensure we don't crash on this invalid VB code + SnippetParser parser = new SnippetParser(SupportedLanguage.VBNet); + INode node = parser.Parse("i == 5"); + Assert.IsTrue(parser.Errors.Count > 0); + } + } +}