Skip to content

Fix missing TS1110 on function signatures with one parameter #823

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 3 commits into from
Sep 10, 2019
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
42 changes: 38 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export class Parser extends DiagnosticEmitter {
if (!suppressErrors) {
this.error(
DiagnosticCode._0_expected,
tn.range(tn.pos), "}"
tn.range(tn.pos), ")"
);
}
return null;
Expand Down Expand Up @@ -620,6 +620,8 @@ export class Parser extends DiagnosticEmitter {
var parameters: ParameterNode[] | null = null;
var thisType: NamedTypeNode | null = null;
var isSignature: bool = false;
var firstParamNameNoType: IdentifierExpression | null = null;
var firstParamKind: ParameterKind = ParameterKind.DEFAULT;

if (tn.skip(Token.CLOSEPAREN)) {
isSignature = true;
Expand Down Expand Up @@ -684,11 +686,29 @@ export class Parser extends DiagnosticEmitter {
if (!parameters) parameters = [ param ];
else parameters.push(param);
} else {
if (!isSignature) {
if (tn.peek() == Token.COMMA) {
isSignature = true;
tn.discard(state);
}
}
if (isSignature) {
let param = new ParameterNode();
param.parameterKind = kind;
param.name = name;
param.type = Node.createOmittedType(tn.range().atEnd);
if (!parameters) parameters = [ param ];
else parameters.push(param);
this.error(
DiagnosticCode.Type_expected,
tn.range()
param.type.range
); // recoverable
} else if (!parameters) {
// on '(' Identifier ^',' we don't yet know whether this is a
// parenthesized or a function type, hence we have to delay the
// respective diagnostic until we know for sure.
firstParamNameNoType = name;
firstParamKind = kind;
}
}
} else {
Expand Down Expand Up @@ -720,8 +740,22 @@ export class Parser extends DiagnosticEmitter {

var returnType: TypeNode | null;
if (tn.skip(Token.EQUALS_GREATERTHAN)) {
isSignature = true;
tn.discard(state);
if (!isSignature) {
isSignature = true;
tn.discard(state);
if (firstParamNameNoType) { // now we know
let param = new ParameterNode();
param.parameterKind = firstParamKind;
param.name = firstParamNameNoType;
param.type = Node.createOmittedType(firstParamNameNoType.range.atEnd);
if (!parameters) parameters = [ param ];
else parameters.push(param);
this.error(
DiagnosticCode.Type_expected,
param.type.range
); // recoverable
}
}
returnType = this.parseType(tn);
if (!returnType) {
this.tryParseSignatureIsSignature = isSignature;
Expand Down
4 changes: 4 additions & 0 deletions tests/parser/function-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var a: () => void;
var b: (a: i32, b: i32) => void;
var c: (a: i32, b: i32) => (a: i32, b: i32) => void;
var d: (a) => void; // TS1110
5 changes: 5 additions & 0 deletions tests/parser/function-type.ts.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var a: () => void;
var b: (a: i32, b: i32) => void;
var c: (a: i32, b: i32) => (a: i32, b: i32) => void;
var d: (a) => void;
// ERROR 1110: "Type expected." in function-type.ts:4:9