Skip to content

Fuzzer fixes - #145

Merged
314eter merged 11 commits into
tree-sitter:masterfrom
314eter:ocamlgrammarfuzzer
Aug 2, 2026
Merged

Fuzzer fixes#145
314eter merged 11 commits into
tree-sitter:masterfrom
314eter:ocamlgrammarfuzzer

Conversation

@314eter

@314eter 314eter commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Some issues found by ocamlgrammarfuzzer:

Include functor

As mentioned in #138 (comment), the include functor support breaks some syntax that was previously valid but rejected by the type checker. Not really an issue in practice, but it's possible to support both by introducting a conflict.

Open module in signatures

Until now, the open_module rule in structures and signatures was the same. But in reality they are slightly different, and it's not possible to support both with one rule. So there is now a separate open_module_signature.

Module type constraints

Weird behaviour by the OCaml parser:

module type T = T with module type T = T -> T
module type T = T with module type T := T -> T

The first one is parsed as (T with module type T = T) -> T, the second one as T with module type T := (T -> T). I don't understand how that's possible (the rules look identical), but we should do the same.

Range patterns

Range patterns were not supported everywhere they should be. This is accepted now:

let f 'a' .. 'z' = ()

Extra constructors

Until now, boolean literals (true, false) and unit (()) were parsed as constants, but the OCaml parser handles them as special constructors. This is now accepted (but please don't):

type t = true of int
type 'a l = [] of 'a list

let f [] [] = true 0

The downside is that [] is not parsed as a list_expression anymore but as the empty_list constructor.

@314eter
314eter force-pushed the ocamlgrammarfuzzer branch from 3e1b21b to 838c8f4 Compare June 21, 2026 23:21
@let-def

let-def commented Jun 22, 2026

Copy link
Copy Markdown

Very nice!

The weird difference between the two module type constraints (parsed as (T with module type T = T) -> T and module type T := (T -> T)) are (likely) due to the following precedence directives (from upstream parser):

%right    COLONEQUAL                    /* expr (e := e := e) */
%right    MINUSGREATER                  /* function_type (t -> t -> t) */
%left     EQUAL   /* expr (e OP e OP e) */

And this is probably accidental. I think it is worth reporting an issue on https://github.com/ocaml/ocaml, at least to raise awareness about this corner-case.

@314eter

314eter commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

I updated the module type constraints fix according to ocaml/ocaml#14978.

@314eter
314eter force-pushed the ocamlgrammarfuzzer branch from f7baaf6 to da5769a Compare August 1, 2026 11:23
@314eter
314eter force-pushed the ocamlgrammarfuzzer branch from da5769a to 4c7622b Compare August 2, 2026 19:26
@314eter

314eter commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Added some more fixes for issues found while fuzzing OxCaml syntax.

@314eter
314eter force-pushed the ocamlgrammarfuzzer branch from 4c7622b to 322d14d Compare August 2, 2026 19:55
@314eter
314eter merged commit b400285 into tree-sitter:master Aug 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants