From f2e9fd3c1f4cf62c6e28382cb424c9eb666856ac Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Tue, 2 May 2023 12:56:29 +0100 Subject: [PATCH] Fix generic type list grammar for func defs The type list for function declarations does not accept defaults, but the grammar incorrectly allowed this --- docs/_pages/grammar.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/_pages/grammar.md b/docs/_pages/grammar.md index 03801602..b451f1c7 100644 --- a/docs/_pages/grammar.md +++ b/docs/_pages/grammar.md @@ -22,12 +22,12 @@ stat = varlist '=' explist | 'function' funcname funcbody | 'local' 'function' NAME funcbody | 'local' bindinglist ['=' explist] | - ['export'] 'type' NAME ['<' GenericTypeParameterList '>'] '=' Type + ['export'] 'type' NAME ['<' GenericTypeListWithDefaults '>'] '=' Type laststat = 'return' [explist] | 'break' | 'continue' funcname = NAME {'.' NAME} [':' NAME] -funcbody = ['<' GenericTypeParameterList '>'] '(' [parlist] ')' [':' ReturnType] block 'end' +funcbody = ['<' GenericTypeList '>'] '(' [parlist] ')' [':' ReturnType] block 'end' parlist = bindinglist [',' '...'] | '...' explist = {exp ','} exp @@ -72,8 +72,12 @@ Type = Type ['|' Type] | Type ['&' Type] -GenericTypePackParameter = NAME '...' ['=' (TypePack | VariadicTypePack | GenericTypePack)] -GenericTypeParameterList = NAME ['=' Type] [',' GenericTypeParameterList] | GenericTypePackParameter {',' GenericTypePackParameter} +GenericTypePackParameter = NAME '...' +GenericTypeList = NAME [',' GenericTypeList] | GenericTypePackParameter {',' GenericTypePackParameter} + +GenericTypePackParameterWithDefault = NAME '...' ['=' (TypePack | VariadicTypePack | GenericTypePack)] +GenericTypeListWithDefaults = NAME ['=' Type] [',' GenericTypeListWithDefaults] | GenericTypePackParameter {',' GenericTypePackParameter} + TypeList = Type [',' TypeList] | '...' Type TypeParams = (Type | TypePack | VariadicTypePack | GenericTypePack) [',' TypeParams] TypePack = '(' [TypeList] ')' @@ -85,5 +89,5 @@ TableProp = NAME ':' Type TablePropOrIndexer = TableProp | TableIndexer PropList = TablePropOrIndexer {fieldsep TablePropOrIndexer} [fieldsep] TableType = '{' PropList '}' -FunctionType = ['<' GenericTypeParameterList '>'] '(' [TypeList] ')' '->' ReturnType +FunctionType = ['<' GenericTypeList '>'] '(' [TypeList] ')' '->' ReturnType ```