Closed nrser closed 10 months ago
I got the same impression. I will compile Janet with your proposed variant and see what happens. Thanks for the heads up.
I can confirm that the behavior with the fix is indeed correct.
I created PR in #1336
Thank you for reporting this error! Please check the fixed version and close this issue, if you find it satisfactory.
https://github.com/janet-lang/janet/blob/772f4c26e82ae0fd111451390c45bbf4763e9ae9/src/core/peg.c#L1655
It looks like this may be using
get_replace
asmin
forjanet_arity
when it should be using themin
variable computed on the previous line?The way I read the current logic is
peg/match
,peg/find
andpeg/find-all
check that arity is zero or greater.peg/replace
andpeg/replace-all
check that arity is one or greater.This looks like a bug because the next line uses
argv[0]
, which is not guaranteed to be there by formatch
,find
andfind-all
. You can see from callingmatch
with no arguments that it clears the arity check and dies trying to handle a peg that isn't there:if you try
peg/replace
with no arguments you'll hit the arity check asget_replace
will be1
:I don't know if this has any actual effect other than less useful error messages. I've just started looking at the peg source regarding adapting it for another use case so I can't say I understand it in any grader sense.