Skip to content

Bugfix for #12315#12428

Merged
gasche merged 1 commit intoocaml:trunkfrom
stedolan:fix-let-rec-optional-typing
Jul 25, 2023
Merged

Bugfix for #12315#12428
gasche merged 1 commit intoocaml:trunkfrom
stedolan:fix-let-rec-optional-typing

Conversation

@stedolan
Copy link
Copy Markdown
Contributor

#12315 introduced a bug in the typing of let rec, causing recursive functions with optional parameters that have defaults to no longer typecheck.

The issue is that the typing of patterns on optional parameters is slightly different depending on whether a default is present:

let f ?(x : int option) () = ()
let g ?(x : int = 5) () = ()

In both cases, the type is ?x:int -> unit -> unit, represented internally as something like this:

(Optional "x", int option) -> ((Nolabel, unit) -> unit)

The type in the function arrow is internally always int option, but the type of the pattern should be int option only when there is no default, and int if there is a default.

#12315 always typechecked like f, causing type errors on code with defaults. (Since the change was to type_approx, this only affects such functions when they are part of a recursive group).

Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

I reviewed the previous PR and didn't find any bug. I reviewed the present PR and don't find any bug either, so it is natural to go ahead and merge.

@gasche gasche merged commit 3301bdc into ocaml:trunk Jul 25, 2023
@yallop
Copy link
Copy Markdown
Member

yallop commented Jul 25, 2023

I think it'd be nice to add the PR number to the existing Changes entry for #12315.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants