Skip to content

Diagnose better error when using generic function by value #2170

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 1 commit into from
Dec 9, 2021
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
12 changes: 6 additions & 6 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7832,10 +7832,10 @@ export class Compiler extends DiagnosticEmitter {

if (typeParameterNodes !== null && typeParameterNodes.length != 0) {
this.error(
DiagnosticCode.Expected_0_arguments_but_got_1,
expression.range, typeParameterNodes.length.toString(), "0"
DiagnosticCode.Type_argument_expected,
expression.range
);
return module.unreachable();
break; // also diagnose 'not a value at runtime'
}

let functionInstance = this.resolver.resolveFunction(
Expand All @@ -7856,10 +7856,10 @@ export class Compiler extends DiagnosticEmitter {
}
}
this.error(
DiagnosticCode.Expression_refers_to_a_static_element_that_does_not_compile_to_a_value_at_runtime,
DiagnosticCode.Expression_does_not_compile_to_a_value_at_runtime,
expression.range
);
return this.module.unreachable();
return module.unreachable();
}

private compileInstanceOfExpression(
Expand Down Expand Up @@ -9207,7 +9207,7 @@ export class Compiler extends DiagnosticEmitter {
}
}
this.error(
DiagnosticCode.Expression_refers_to_a_static_element_that_does_not_compile_to_a_value_at_runtime,
DiagnosticCode.Expression_does_not_compile_to_a_value_at_runtime,
expression.range
);
return this.module.unreachable();
Expand Down
4 changes: 2 additions & 2 deletions src/diagnosticMessages.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export enum DiagnosticCode {
_0_keyword_cannot_be_used_here = 230,
A_class_with_a_constructor_explicitly_returning_something_else_than_this_must_be_final = 231,
Property_0_is_always_assigned_before_being_used = 233,
Expression_refers_to_a_static_element_that_does_not_compile_to_a_value_at_runtime = 234,
Expression_does_not_compile_to_a_value_at_runtime = 234,
Importing_the_table_disables_some_indirect_call_optimizations = 901,
Exporting_the_table_disables_some_indirect_call_optimizations = 902,
Expression_compiles_to_a_dynamic_check_at_runtime = 903,
Expand Down Expand Up @@ -237,7 +237,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string {
case 230: return "'{0}' keyword cannot be used here.";
case 231: return "A class with a constructor explicitly returning something else than 'this' must be '@final'.";
case 233: return "Property '{0}' is always assigned before being used.";
case 234: return "Expression refers to a static element that does not compile to a value at runtime.";
case 234: return "Expression does not compile to a value at runtime.";
case 901: return "Importing the table disables some indirect call optimizations.";
case 902: return "Exporting the table disables some indirect call optimizations.";
case 903: return "Expression compiles to a dynamic check at runtime.";
Expand Down
2 changes: 1 addition & 1 deletion src/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"'{0}' keyword cannot be used here.": 230,
"A class with a constructor explicitly returning something else than 'this' must be '@final'.": 231,
"Property '{0}' is always assigned before being used.": 233,
"Expression refers to a static element that does not compile to a value at runtime.": 234,
"Expression does not compile to a value at runtime.": 234,

"Importing the table disables some indirect call optimizations.": 901,
"Exporting the table disables some indirect call optimizations.": 902,
Expand Down