Skip to content
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
2 changes: 1 addition & 1 deletion src/parser/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ module.exports = {
nullable = true;
this.next();
}
let type = this.read_type();
let type = this.read_types();
if (nullable && !type) {
this.raiseError(
"Expecting a type definition combined with nullable operator"
Expand Down
2 changes: 1 addition & 1 deletion src/parser/expr.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ module.exports = {
nullable = true;
this.next();
}
returnType = this.read_type();
returnType = this.read_types();
}
if (this.expect(this.tok.T_DOUBLE_ARROW)) this.next();
const body = this.read_expr();
Expand Down
22 changes: 17 additions & 5 deletions src/parser/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.exports = {
nullable = true;
this.next();
}
returnType = this.read_type();
returnType = this.read_types();
}
if (type === 1) {
// closure
Expand Down Expand Up @@ -202,14 +202,14 @@ module.exports = {
const node = this.node("parameter");
let parameterName = null;
let value = null;
let type = null;
let types = null;
let nullable = false;
if (this.token === "?") {
this.next();
nullable = true;
}
type = this.read_type();
if (nullable && !type) {
types = this.read_types();
if (nullable && !types) {
this.raiseError(
"Expecting a type definition combined with nullable operator"
);
Expand All @@ -225,7 +225,19 @@ module.exports = {
if (this.token == "=") {
value = this.next().read_expr();
}
return node(parameterName, type, value, isRef, isVariadic, nullable);
return node(parameterName, types, value, isRef, isVariadic, nullable);
},
read_types() {
const types = [];
let type = this.read_type();
if (!type) return null;
types.push(type);
while (this.token === "|") {
this.next();
type = this.read_type();
types.push(type);
}
return types.length === 0 ? null : types;
},
/**
* Reads a list of arguments
Expand Down
Loading