From ef2c0c623e7518bc67b94a24fabf7f84c022448b Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Sun, 9 Sep 2018 18:21:30 -0700 Subject: [PATCH] Improve error message for accessing method like a field (#253) --- src/compiler.ts | 7 +++++++ src/diagnosticMessages.generated.ts | 2 ++ src/diagnosticMessages.json | 1 + 3 files changed, 10 insertions(+) diff --git a/src/compiler.ts b/src/compiler.ts index cb2cbe3d..672aebd8 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6727,6 +6727,13 @@ export class Compiler extends DiagnosticEmitter { case ElementKind.PROPERTY: {// instance property (here: getter) return this.compileGetter(target, propertyAccess); } + case ElementKind.FUNCTION_PROTOTYPE: { + this.error( + DiagnosticCode.Cannot_access_method_0_without_calling_it_as_it_requires_this_to_be_set, + propertyAccess.range, (target).simpleName + ); + return module.createUnreachable(); + } } this.error( DiagnosticCode.Operation_not_supported, diff --git a/src/diagnosticMessages.generated.ts b/src/diagnosticMessages.generated.ts index a9672b63..fd1f65eb 100644 --- a/src/diagnosticMessages.generated.ts +++ b/src/diagnosticMessages.generated.ts @@ -28,6 +28,7 @@ export enum DiagnosticCode { Optional_parameter_must_have_an_initializer = 215, Constructor_of_class_0_must_not_require_any_arguments = 216, Function_0_cannot_be_inlined_into_itself = 217, + Cannot_access_method_0_without_calling_it_as_it_requires_this_to_be_set = 218, Unterminated_string_literal = 1002, Identifier_expected = 1003, _0_expected = 1005, @@ -147,6 +148,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 215: return "Optional parameter must have an initializer."; case 216: return "Constructor of class '{0}' must not require any arguments."; case 217: return "Function '{0}' cannot be inlined into itself."; + case 218: return "Cannot access method '{0}' without calling it as it requires 'this' to be set."; case 1002: return "Unterminated string literal."; case 1003: return "Identifier expected."; case 1005: return "'{0}' expected."; diff --git a/src/diagnosticMessages.json b/src/diagnosticMessages.json index fca90852..647a172e 100644 --- a/src/diagnosticMessages.json +++ b/src/diagnosticMessages.json @@ -20,6 +20,7 @@ "Optional parameter must have an initializer.": 215, "Constructor of class '{0}' must not require any arguments.": 216, "Function '{0}' cannot be inlined into itself.": 217, + "Cannot access method '{0}' without calling it as it requires 'this' to be set.": 218, "Unterminated string literal.": 1002, "Identifier expected.": 1003,