Adds support for the never return type from the no_return RFC

pull/315/head
Christian Frøystad 2022-06-01 09:26:02 +07:00 committed by Christian Frøystad
parent 20b20d8d77
commit fdbef3621b
5 changed files with 5853 additions and 5785 deletions

@ -493,6 +493,8 @@ module.exports = grammar({
)
),
bottom_type: $ => 'never',
union_type: $ => prec.right(pipeSep1($._types)),
primitive_type: $ => choice(
@ -525,7 +527,7 @@ module.exports = grammar({
keyword('unset', false)
),
_return_type: $ => seq(':', field('return_type', $._type)),
_return_type: $ => seq(':', field('return_type', choice($._type, $.bottom_type))),
const_element: $ => seq(
choice($.name, alias($._reserved_identifier, $.name)), '=', $._expression

17
src/grammar.json vendored

@ -2534,6 +2534,10 @@
}
]
},
"bottom_type": {
"type": "STRING",
"value": "never"
},
"union_type": {
"type": "PREC_RIGHT",
"value": 0,
@ -2685,8 +2689,17 @@
"type": "FIELD",
"name": "return_type",
"content": {
"type": "SYMBOL",
"name": "_type"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type"
},
{
"type": "SYMBOL",
"name": "bottom_type"
}
]
}
}
]

@ -389,6 +389,10 @@
{
"type": "_type",
"named": true
},
{
"type": "bottom_type",
"named": true
}
]
}
@ -575,6 +579,10 @@
{
"type": "_type",
"named": true
},
{
"type": "bottom_type",
"named": true
}
]
}
@ -2219,6 +2227,10 @@
{
"type": "_type",
"named": true
},
{
"type": "bottom_type",
"named": true
}
]
}
@ -2839,6 +2851,10 @@
{
"type": "_type",
"named": true
},
{
"type": "bottom_type",
"named": true
}
]
}
@ -4971,6 +4987,10 @@
"type": "boolean",
"named": true
},
{
"type": "bottom_type",
"named": true
},
{
"type": "break",
"named": false
@ -5085,11 +5105,11 @@
},
{
"type": "float",
"named": true
"named": false
},
{
"type": "float",
"named": false
"named": true
},
{
"type": "fn",

11588
src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -29,6 +29,7 @@ Primitive types
function a(): int {}
function b(): callable {}
function c(): iterable {}
function d(): never {}
---
@ -45,6 +46,10 @@ function c(): iterable {}
(function_definition
(name) (formal_parameters)
(union_type (primitive_type))
(compound_statement))
(function_definition
(name) (formal_parameters)
(bottom_type)
(compound_statement)))
=======================