Skip to content

Commit

Permalink
Emit an error instead of aborting when inferring unused type paramete…
Browse files Browse the repository at this point in the history
…rs (#766)
  • Loading branch information
dcodeIO committed Aug 21, 2019
1 parent 4a4cea5 commit a08c7cb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/compiler.ts
Expand Up @@ -5868,8 +5868,21 @@ export class Compiler extends DiagnosticEmitter {
}
let resolvedTypeArguments = new Array<Type>(numTypeParameters);
for (let i = 0; i < numTypeParameters; ++i) {
let inferredType = assert(inferredTypes.get(typeParameterNodes[i].name.text)); // TODO
resolvedTypeArguments[i] = inferredType;
let name = typeParameterNodes[i].name.text;
if (inferredTypes.has(name)) {
let inferredType = inferredTypes.get(name);
if (inferredType) {
resolvedTypeArguments[i] = inferredType;
continue;
}
}
// unused template, e.g. `function test<T>(): void {...}` called as `test()`
// invalid because the type is effectively unknown inside the function body
this.error(
DiagnosticCode.Type_argument_expected,
expression.expression.range.atEnd
);
return this.module.unreachable();
}
instance = this.resolver.resolveFunction(
prototype,
Expand Down

0 comments on commit a08c7cb

Please sign in to comment.