Fix regression where parse errors are not correctly reported

This commit is contained in:
Sam Vervaeck 2020-06-16 22:24:01 +02:00
parent 0019f37749
commit 9c5a8b9e59
3 changed files with 14 additions and 8 deletions

View file

@ -2,7 +2,7 @@
import * as fs from "fs" import * as fs from "fs"
import chalk from "chalk" import chalk from "chalk"
import { Syntax } from "./ast"; import { Syntax } from "./ast";
import {format, MapLike, FormatArg, countDigits, mapValues, prettyPrint, assert} from "./util"; import {format, MapLike, FormatArg, countDigits, mapValues, prettyPrint, assert, isPlainObject, isPrimitive, JsonObject, Json} from "./util";
import { BOLT_DIAG_NUM_EXTRA_LINES } from "./constants"; import { BOLT_DIAG_NUM_EXTRA_LINES } from "./constants";
import { TextPos, TextFile, TextSpan } from "./text"; import { TextPos, TextFile, TextSpan } from "./text";
@ -125,7 +125,7 @@ export class DiagnosticPrinter {
out += chalk.bold.yellow(`${span.file.origPath}:${span.start.line}:${span.start.column}: `); out += chalk.bold.yellow(`${span.file.origPath}:${span.start.line}:${span.start.column}: `);
} }
if (diagnostic.args !== undefined) { if (diagnostic.args !== undefined) {
out += format(diagnostic.message, mapValues(diagnostic.args, prettyPrint)) + '\n'; out += format(diagnostic.message, diagnostic.args) + '\n';
} else { } else {
out += diagnostic.message + '\n'; out += diagnostic.message + '\n';
} }

View file

@ -19,7 +19,7 @@ import { TypeChecker } from "./types"
import { CheckInvalidFilePaths, CheckTypeAssignments, CheckReferences } from "./checks" import { CheckInvalidFilePaths, CheckTypeAssignments, CheckReferences } from "./checks"
import { SymbolResolver, BoltSymbolResolutionStrategy } from "./resolver" import { SymbolResolver, BoltSymbolResolutionStrategy } from "./resolver"
import { Evaluator } from "./evaluator" import { Evaluator } from "./evaluator"
import { getNodeLanguage, ParseError, ScanError } from "./common" import { getNodeLanguage, ParseError, ScanError, describeKind } from "./common"
import { Package, loadPackageMetadata } from "./package" import { Package, loadPackageMetadata } from "./package"
import { TextFile } from "./text" import { TextFile } from "./text"
import { Scanner } from "./scanner" import { Scanner } from "./scanner"
@ -191,7 +191,7 @@ export class Frontend {
} else if (e instanceof ParseError) { } else if (e instanceof ParseError) {
this.diagnostics.add({ this.diagnostics.add({
message: E_PARSE_ERROR, message: E_PARSE_ERROR,
args: { actual: kindToString(e.actual.kind), expected: e.expected.map(kindToString) }, args: { actual: describeKind(e.actual.kind), expected: e.expected.map(describeKind) },
node: e.actual, node: e.actual,
severity: 'fatal', severity: 'fatal',
}); });

View file

@ -627,6 +627,9 @@ type FormatModifierFn = (value: any) => any;
const FORMAT_MODIFIERS: MapLike<FormatModifierFn> = { const FORMAT_MODIFIERS: MapLike<FormatModifierFn> = {
enum(elements) { enum(elements) {
return enumOr(elements); return enumOr(elements);
},
pretty(value) {
return value.map(prettyPrint);
} }
} }
@ -643,17 +646,20 @@ export function format(message: string, data: MapLike<FormatArg>) {
switch (mode) { switch (mode) {
case FormatScanMode.ScanningParamModifier: case FormatScanMode.ScanningParamModifier:
if (ch === '}') { if (ch === '}') {
modifiers.push(modifierName);
push();
} else if (ch === ':') {
if (modifierName.length === 0) { if (modifierName.length === 0) {
throw new Error(`Parameter modfifier name in format string is empty.`) throw new Error(`Parameter modfifier name in format string is empty.`)
} }
modifiers.push(modifierName); modifiers.push(modifierName);
modifierName = ''; push();
} else if (ch === ':') {
if (modifierName.length > 0) {
modifiers.push(modifierName);
modifierName = '';
}
} else { } else {
modifierName += ch; modifierName += ch;
} }
break;
case FormatScanMode.ScanningParamName: case FormatScanMode.ScanningParamName:
if (ch === '}') { if (ch === '}') {
push(); push();