From b2e8ef2a1339bc5e8940e47ec776b3a09f5b9bf3 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 18 Mar 2013 18:07:04 +0100 Subject: [PATCH] Fix InvalidOperationException in semantic highlighter. --- .../Project/Src/CSharpSemanticHighlighter.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs index 3124cd8801..f2097e94dd 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs @@ -340,8 +340,13 @@ namespace CSharpBinding int endOffset = lineStartOffset + (end.Line == lineNumber ? end.Column - 1 : line.DocumentLine.Length); if (line.Sections.Count > 0) { HighlightedSection prevSection = line.Sections.Last(); - if (startOffset < prevSection.Offset + prevSection.Length) - throw new InvalidOperationException("Cannot create unordered highlighting section"); + if (startOffset < prevSection.Offset + prevSection.Length) { + // The mcs parser sometimes creates strange ASTs with duplicate nodes + // when there are syntax errors (e.g. "int A() public static void Main() {}"), + // so we'll silently ignore duplicate colorization. + return; + //throw new InvalidOperationException("Cannot create unordered highlighting section"); + } } line.Sections.Add(new HighlightedSection { Offset = startOffset,