Skip to content

Commit a962528

Browse files
authored
Diagnose better error when using generic function by value (#2170)
1 parent fd1e1df commit a962528

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/compiler.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -7832,10 +7832,10 @@ export class Compiler extends DiagnosticEmitter {
78327832

78337833
if (typeParameterNodes !== null && typeParameterNodes.length != 0) {
78347834
this.error(
7835-
DiagnosticCode.Expected_0_arguments_but_got_1,
7836-
expression.range, typeParameterNodes.length.toString(), "0"
7835+
DiagnosticCode.Type_argument_expected,
7836+
expression.range
78377837
);
7838-
return module.unreachable();
7838+
break; // also diagnose 'not a value at runtime'
78397839
}
78407840

78417841
let functionInstance = this.resolver.resolveFunction(
@@ -7856,10 +7856,10 @@ export class Compiler extends DiagnosticEmitter {
78567856
}
78577857
}
78587858
this.error(
7859-
DiagnosticCode.Expression_refers_to_a_static_element_that_does_not_compile_to_a_value_at_runtime,
7859+
DiagnosticCode.Expression_does_not_compile_to_a_value_at_runtime,
78607860
expression.range
78617861
);
7862-
return this.module.unreachable();
7862+
return module.unreachable();
78637863
}
78647864

78657865
private compileInstanceOfExpression(
@@ -9207,7 +9207,7 @@ export class Compiler extends DiagnosticEmitter {
92079207
}
92089208
}
92099209
this.error(
9210-
DiagnosticCode.Expression_refers_to_a_static_element_that_does_not_compile_to_a_value_at_runtime,
9210+
DiagnosticCode.Expression_does_not_compile_to_a_value_at_runtime,
92119211
expression.range
92129212
);
92139213
return this.module.unreachable();

src/diagnosticMessages.generated.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export enum DiagnosticCode {
4848
_0_keyword_cannot_be_used_here = 230,
4949
A_class_with_a_constructor_explicitly_returning_something_else_than_this_must_be_final = 231,
5050
Property_0_is_always_assigned_before_being_used = 233,
51-
Expression_refers_to_a_static_element_that_does_not_compile_to_a_value_at_runtime = 234,
51+
Expression_does_not_compile_to_a_value_at_runtime = 234,
5252
Importing_the_table_disables_some_indirect_call_optimizations = 901,
5353
Exporting_the_table_disables_some_indirect_call_optimizations = 902,
5454
Expression_compiles_to_a_dynamic_check_at_runtime = 903,
@@ -237,7 +237,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string {
237237
case 230: return "'{0}' keyword cannot be used here.";
238238
case 231: return "A class with a constructor explicitly returning something else than 'this' must be '@final'.";
239239
case 233: return "Property '{0}' is always assigned before being used.";
240-
case 234: return "Expression refers to a static element that does not compile to a value at runtime.";
240+
case 234: return "Expression does not compile to a value at runtime.";
241241
case 901: return "Importing the table disables some indirect call optimizations.";
242242
case 902: return "Exporting the table disables some indirect call optimizations.";
243243
case 903: return "Expression compiles to a dynamic check at runtime.";

src/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"'{0}' keyword cannot be used here.": 230,
4444
"A class with a constructor explicitly returning something else than 'this' must be '@final'.": 231,
4545
"Property '{0}' is always assigned before being used.": 233,
46-
"Expression refers to a static element that does not compile to a value at runtime.": 234,
46+
"Expression does not compile to a value at runtime.": 234,
4747

4848
"Importing the table disables some indirect call optimizations.": 901,
4949
"Exporting the table disables some indirect call optimizations.": 902,

0 commit comments

Comments
 (0)