Skip to content

Improve error messages #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,637 changes: 1,895 additions & 1,742 deletions src/builtins.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,6 @@ export namespace CommonSymbols {
}

// shared
export { Feature } from "../std/assembly/shared/feature";
export { Feature, featureToString } from "../std/assembly/shared/feature";
export { Target } from "../std/assembly/shared/target";
export { Typeinfo, TypeinfoFlags } from "../std/assembly/shared/typeinfo";
88 changes: 44 additions & 44 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,8 @@ export class Compiler extends DiagnosticEmitter {
// Importing mutable globals is not supported in the MVP
} else {
this.error(
DiagnosticCode.Operation_not_supported,
global.declaration.range
DiagnosticCode.Feature_0_is_not_enabled,
global.declaration.range, "mutable-globals"
);
}
return false;
Expand Down Expand Up @@ -1258,8 +1258,8 @@ export class Compiler extends DiagnosticEmitter {
let decoratorNodes = instance.decoratorNodes;
let decorator = assert(findDecorator(DecoratorKind.EXTERNAL, decoratorNodes));
this.error(
DiagnosticCode.Operation_not_supported,
decorator.range
DiagnosticCode.Decorator_0_is_not_valid_here,
decorator.range, "external"
);
}

Expand Down Expand Up @@ -1447,7 +1447,7 @@ export class Compiler extends DiagnosticEmitter {
): void {
// TODO
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
declaration.range
);
}
Expand Down Expand Up @@ -1765,7 +1765,7 @@ export class Compiler extends DiagnosticEmitter {
case NodeKind.TYPEDECLARATION: {
// TODO: integrate inner type declaration into flow
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
statement.range
);
stmt = module.unreachable();
Expand Down Expand Up @@ -1835,7 +1835,7 @@ export class Compiler extends DiagnosticEmitter {
var module = this.module;
if (statement.label) {
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
statement.label.range
);
return module.unreachable();
Expand Down Expand Up @@ -1869,7 +1869,7 @@ export class Compiler extends DiagnosticEmitter {
var label = statement.label;
if (label) {
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
label.range
);
return module.unreachable();
Expand Down Expand Up @@ -2415,7 +2415,7 @@ export class Compiler extends DiagnosticEmitter {
// TODO: can't yet support something like: try { return ... } finally { ... }
// worthwhile to investigate lowering returns to block results (here)?
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
statement.range
);
return this.module.unreachable();
Expand Down Expand Up @@ -2859,7 +2859,7 @@ export class Compiler extends DiagnosticEmitter {
}
default: {
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
expression.range
);
expr = this.module.unreachable();
Expand Down Expand Up @@ -3651,7 +3651,7 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.ANYREF: {
// TODO: ref.eq
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
expression.range
);
expr = module.unreachable();
Expand Down Expand Up @@ -3748,7 +3748,7 @@ export class Compiler extends DiagnosticEmitter {
case TypeKind.ANYREF: {
// TODO: !ref.eq
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
expression.range
);
expr = module.unreachable();
Expand Down Expand Up @@ -5250,7 +5250,7 @@ export class Compiler extends DiagnosticEmitter {
}
default: {
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
expression.range
);
return this.module.unreachable();
Expand Down Expand Up @@ -5445,7 +5445,7 @@ export class Compiler extends DiagnosticEmitter {
}
}
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
valueExpression.range
);
return module.unreachable();
Expand Down Expand Up @@ -5999,10 +5999,18 @@ export class Compiler extends DiagnosticEmitter {

// not supported
default: {
this.error(
DiagnosticCode.Operation_not_supported,
expression.range
);
let type = this.resolver.getTypeOfElement(target);
if (type) {
this.error(
DiagnosticCode.Type_0_has_no_call_signatures,
expression.range, type.toString()
);
} else {
this.error(
DiagnosticCode.Expression_cannot_be_represented_by_a_type,
expression.range
);
}
return module.unreachable();
}
}
Expand Down Expand Up @@ -6046,22 +6054,14 @@ export class Compiler extends DiagnosticEmitter {
}

// now compile the builtin, which usually returns a block of code that replaces the call.
var expr = compileBuiltinCall(
return compileBuiltinCall(
this,
prototype,
typeArguments,
expression.arguments,
contextualType,
expression
);
if (!expr) {
this.error(
DiagnosticCode.Operation_not_supported,
expression.range
);
return this.module.unreachable();
}
return expr;
}

/**
Expand All @@ -6079,7 +6079,7 @@ export class Compiler extends DiagnosticEmitter {
var thisType = signature.thisType;
if (hasThis != (thisType != null)) {
this.error(
DiagnosticCode.Operation_not_supported, // TODO: better message?
DiagnosticCode.The_this_types_of_each_signature_are_incompatible,
reportNode.range
);
return false;
Expand All @@ -6089,7 +6089,7 @@ export class Compiler extends DiagnosticEmitter {
var hasRest = signature.hasRest;
if (hasRest) {
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
reportNode.range
);
return false;
Expand Down Expand Up @@ -6126,7 +6126,7 @@ export class Compiler extends DiagnosticEmitter {
// Library files may always use unsafe features
if (this.options.noUnsafe && !reportNode.range.source.isLibrary) {
this.error(
DiagnosticCode.Expression_is_unsafe,
DiagnosticCode.Operation_is_unsafe,
reportNode.range
);
}
Expand Down Expand Up @@ -7312,7 +7312,7 @@ export class Compiler extends DiagnosticEmitter {
}
}
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
expression.range
);
return this.module.unreachable();
Expand Down Expand Up @@ -7390,8 +7390,8 @@ export class Compiler extends DiagnosticEmitter {
);
} else {
this.error(
DiagnosticCode.Operation_not_supported,
expression.range
DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2,
expression.range, "instanceof", actualType.toString(), expectedType.toString()
);
}
}
Expand Down Expand Up @@ -7432,8 +7432,8 @@ export class Compiler extends DiagnosticEmitter {
);
} else {
this.error(
DiagnosticCode.Operation_not_supported,
expression.range
DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2,
expression.range, "instanceof", actualType.toString(), expectedType.toString()
);
}
}
Expand Down Expand Up @@ -7468,8 +7468,8 @@ export class Compiler extends DiagnosticEmitter {
}
}
this.error(
DiagnosticCode.Operation_not_supported,
expression.range
DiagnosticCode.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly,
expression.range, "T"
);
return module.unreachable();
}
Expand Down Expand Up @@ -7515,7 +7515,7 @@ export class Compiler extends DiagnosticEmitter {
// case LiteralKind.REGEXP:
}
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
expression.range
);
this.currentType = contextualType;
Expand Down Expand Up @@ -7777,7 +7777,7 @@ export class Compiler extends DiagnosticEmitter {
if (!target) return module.unreachable();
if (target.kind != ElementKind.CLASS_PROTOTYPE) {
this.error(
DiagnosticCode.Cannot_use_new_with_an_expression_whose_type_lacks_a_construct_signature,
DiagnosticCode.This_expression_is_not_constructable,
expression.expression.range
);
return this.module.unreachable();
Expand Down Expand Up @@ -8038,7 +8038,7 @@ export class Compiler extends DiagnosticEmitter {
}
}
this.error(
DiagnosticCode.Operation_not_supported,
DiagnosticCode.Not_implemented,
expression.range
);
return module.unreachable();
Expand Down Expand Up @@ -8190,8 +8190,8 @@ export class Compiler extends DiagnosticEmitter {
}
}
this.error(
DiagnosticCode.Operation_not_supported,
expression.range
DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1,
expression.range, "++", this.currentType.toString()
);
if (tempLocal) flow.freeTempLocal(tempLocal);
return module.unreachable();
Expand Down Expand Up @@ -8279,8 +8279,8 @@ export class Compiler extends DiagnosticEmitter {
}
}
this.error(
DiagnosticCode.Operation_not_supported,
expression.range
DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1,
expression.range, "--", this.currentType.toString()
);
if (tempLocal) flow.freeTempLocal(tempLocal);
return module.unreachable();
Expand Down
Loading