Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for list emptiness before checking variants #178

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lib/pythongen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ let rec typecheck : type a. a typ -> string -> t list =
variants
in
let check_contents =
List.fold_left
(fun acc x -> List.concat [ acc; check false x ])
(check true (List.hd variants_to_check))
(List.tl variants_to_check)
match variants_to_check with
| [] -> []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vincent-lau I think @mseri meant that you didn't need the | [] -> [] if you used | v :: vs -> form

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need both, the second one pattern matches only on nonempty lists

| v :: vs ->
List.fold_left
(fun acc x -> List.concat [ acc; check false x ])
(check true v) vs
in
let all_tags = List.map (fun (BoxedTag t) -> t.tname) variants in
let pylist =
Expand Down