1
Vote

NullErrorSink throws unexpected exceptions, ErrorCounter miscounts...

description

Microsoft.Scripting.ErrorSink now has had a second virtual overload of the Add() method to handle cases where a SourceUnit is not available.
The embedded derrived classes NullErrorSink and ErrorCounter need a small additions to mirror this, (or minor restructuring so that only one of the methods is virtual.) In both cases, the there are unintended consequences for the lack of these overrides.
 
For NullErrorSink, errors added through the new overload result in an exception being thrown. The required change is trivial, add the second override with an empty body as shown below:
 
        public override void Add(string message, string path, string code, string line, SourceSpan span, int errorCode, Severity severity) {
    }
 
For ErrorCounter, it fails to count errors added through the new overload. A fix is nearly as simple, it should read:
 
    public override void Add(string message, string path, string code, string line, SourceSpan span, int errorCode, Severity severity) {
        CountError(severity);
        _sink.Add(message, path, code, line, span, errorCode, severity) {
    }

comments