Skip to content

Instantly share code, notes, and snippets.

@AleksandrSl
Last active August 26, 2025 11:37
Show Gist options
  • Select an option

  • Save AleksandrSl/42261dff5f6524e48684bb7701bf0d45 to your computer and use it in GitHub Desktop.

Select an option

Save AleksandrSl/42261dff5f6524e48684bb7701bf0d45 to your computer and use it in GitHub Desktop.
Parser errors example

Yes, I’m not the brightest candle on the cake, so I made similar errors.

The next rule in question is

type_params ::= (variadic_type_pack | generic_type_pack | type_pack | type) (',' type_params)?

It parses generic parameters inside the types. The type that gives the error is

return something :: T<(string) -> string>

To get the full understanding you should know that Lua supports return of multiple values from functions, and it’s not like in Python where return 1, 2 returns you a tuple, as Lua returns separate values. To type this in Luau a type pack has been introduced and it looks like this: (number, number) . Maybe now you see where this is going.

I had one more error in the same parsing rule before, having type on the first place. To fix it I just slapped it to the last place, and got another bug 🫠. First part of the function signature looks exactly like a type pack, but function is longer so it should come before it. As a fix I swapped type and type_pack which works good so far.

One more related funny story was that I had two bugs which led to the incorrectly parsed program without any errors.

local function identity<T...>(...: T...): T...
   return ...
end

The code above was actually parsed as

local function identity<T...>(...: T...): T -- return type is just T
   ... -- reference to the function argument
   return ...
end

I found out about this error when I prohibited non function calls as statements. And then “fixed” the rule mentioned above 😹

Here's one more stupid rule for you to correct, all the hints have already been laid out for you.

method_name ::= ID ('.' ID)* (':' ID | '.' ID)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment