diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs index 176d5546e7..e9b4542388 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs @@ -94,7 +94,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp if (expr.StartLocation.IsEmpty) expr.StartLocation = startLocation; if (expr.EndLocation.IsEmpty) - expr.EndLocation = t.EndLocation; + expr.EndLocation = (t ?? la).EndLocation; expr.AcceptVisitor(new SetParentVisitor(), null); } Expect(Tokens.EOF); @@ -120,7 +120,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp } BlockEnd(); - blockStmt.EndLocation = t.EndLocation; + // if lexer didn't return any tokens, use position of the EOF token in "la" + blockStmt.EndLocation = (t ?? la).EndLocation; Expect(Tokens.EOF); blockStmt.AcceptVisitor(new SetParentVisitor(), null); return blockStmt;