Skip to content

Commit ef2c0c6

Browse files
andy-hansondcodeIO
authored andcommitted
Improve error message for accessing method like a field (AssemblyScript#253)
1 parent 3605630 commit ef2c0c6

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/compiler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6727,6 +6727,13 @@ export class Compiler extends DiagnosticEmitter {
67276727
case ElementKind.PROPERTY: {// instance property (here: getter)
67286728
return this.compileGetter(<Property>target, propertyAccess);
67296729
}
6730+
case ElementKind.FUNCTION_PROTOTYPE: {
6731+
this.error(
6732+
DiagnosticCode.Cannot_access_method_0_without_calling_it_as_it_requires_this_to_be_set,
6733+
propertyAccess.range, (<FunctionPrototype>target).simpleName
6734+
);
6735+
return module.createUnreachable();
6736+
}
67306737
}
67316738
this.error(
67326739
DiagnosticCode.Operation_not_supported,

src/diagnosticMessages.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export enum DiagnosticCode {
2828
Optional_parameter_must_have_an_initializer = 215,
2929
Constructor_of_class_0_must_not_require_any_arguments = 216,
3030
Function_0_cannot_be_inlined_into_itself = 217,
31+
Cannot_access_method_0_without_calling_it_as_it_requires_this_to_be_set = 218,
3132
Unterminated_string_literal = 1002,
3233
Identifier_expected = 1003,
3334
_0_expected = 1005,
@@ -147,6 +148,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string {
147148
case 215: return "Optional parameter must have an initializer.";
148149
case 216: return "Constructor of class '{0}' must not require any arguments.";
149150
case 217: return "Function '{0}' cannot be inlined into itself.";
151+
case 218: return "Cannot access method '{0}' without calling it as it requires 'this' to be set.";
150152
case 1002: return "Unterminated string literal.";
151153
case 1003: return "Identifier expected.";
152154
case 1005: return "'{0}' expected.";

src/diagnosticMessages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"Optional parameter must have an initializer.": 215,
2121
"Constructor of class '{0}' must not require any arguments.": 216,
2222
"Function '{0}' cannot be inlined into itself.": 217,
23+
"Cannot access method '{0}' without calling it as it requires 'this' to be set.": 218,
2324

2425
"Unterminated string literal.": 1002,
2526
"Identifier expected.": 1003,

0 commit comments

Comments
 (0)