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

Allow to omit parent type in constructor reference. #933

Merged
merged 10 commits into from
Dec 6, 2023

Conversation

panglesd
Copy link
Collaborator

@panglesd panglesd commented Mar 2, 2023

Fix #447.

Currently, it is not possible to refer to constructors without specifying the parent type, except if they are in scope.

This PR fixes this by extending parents of constructor references to signatures.

The first commit adds the test. The second fixes the issue similarly to what it is done with field (which already allows omitting the type parent). The last two commits are refactoring that improve the guarantee given by the subtyping.

(Made with @EmileTrotignon)

Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

Looks good :)

(* Let's pretend we didn't see the field and say we didn't find anything. *)
Error (`Find_by_name (`Cons, name))

let in_parent _env (parent : label_parent_lookup_result) name =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps we need a _lookup_result that correspond to Reference.Parent to remove the impossible cases ?

type t = Foo
end

(** {!M.constructor-Foo}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It could be worth checking for M.Foo and M.t.Foo, which works fine in my testing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

@panglesd panglesd force-pushed the fix_447 branch 2 times, most recently from 3164be7 to a834b52 Compare March 30, 2023 06:36
@dbuenzli
Copy link
Contributor

@panglesd since you are in the area do you maybe see a fix for #932 at the same time ?

@panglesd
Copy link
Collaborator Author

The new commits consist of:

About #933 (comment), in the end I'm not sure yet that it's a good idea. The code is nicer, more specific and less case to handle. But, the error message in case of a class found as a parent of a constructor is less explicit: see the error message before and after in this case.

do you maybe see a fix for #932 at the same time ?

Not directly, but since this PR made me much more comfortable with this part of the code, I'll have a look!

@Julow
Copy link
Collaborator

Julow commented Mar 30, 2023

But, the error message in case of a class found as a parent of a constructor is less explicit

This error message could perhaps be implemented in general ? The previous message is not satisfactory because it seems to be about t.A where it's actually about t:

Warning: Failed to resolve reference unresolvedroot(t).A is of kind class but expected signature or type

A new kind of error message is needed: "<parent> is of unexpected kind".

@EmileTrotignon EmileTrotignon added this to the 2.4.0 milestone Dec 5, 2023
@EmileTrotignon
Copy link
Collaborator

I think this should be rebased, a better error message added, and then merged.

EmileTrotignon and others added 5 commits December 6, 2023 09:38
Co-authored-by: Paul-Elliot <peada@free.fr>
Signed-off-by: Paul-Elliot <peada@free.fr>
This allows to omit the type the constructor is coming from. The constructor
will be fetched from the environment.
The commit does this in a similar way to fields, which can have type `parent`
for parents of type references.

Co-authored-by: Paul-Elliot <peada@free.fr>
Signed-off-by: Paul-Elliot <peada@free.fr>
Indeed, `parent` is for constructor and fields: they can only have signature or
datatype as parent.

Signed-off-by: Paul-Elliot <peada@free.fr>
Co-authored-by: Emile Trotignon <emile@tarides.com>
Resolved references/ids already always had datatype as parent, but it is now
enforced by the subtyping system.

The reason we cannot symmetrically do the same for fields is the following:
```ocaml
type t = ..

type t += Inline of { a : int}
```
In this example, `a` cannot have a `datatype` as parent. Parent for fields
should ideally be `[datatype | constructor | extension]`.

Signed-off-by: Paul-Elliot <peada@free.fr>
Co-authored-by: Emile Trotignon <emile@tarides.com>
The former was too generic. Added some comments at the definition.

Signed-off-by: Paul-Elliot <peada@free.fr>
since they are not used in resolved ref and id of cosntructor: for those, the
parent is a type.

Signed-off-by: Paul-Elliot <peada@free.fr>
To match the semantics of references

Signed-off-by: Paul-Elliot <peada@free.fr>
This changes the error message, from "wrong type", to unresolved.

Signed-off-by: Paul-Elliot <peada@free.fr>
Signed-off-by: Paul-Elliot <peada@free.fr>
Signed-off-by: Paul-Elliot <peada@free.fr>
@panglesd
Copy link
Collaborator Author

panglesd commented Dec 6, 2023

This is rebased, but I did not implement a better error message. Do you think it could be implemented in another PR? From what I remember from March 30, it is some non-negligible amount of work, but I don't remember why.

Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

The error message is a secondary issue and should be discussed separately. This is good to merge :)

@Julow Julow merged commit 5a054ff into ocaml:master Dec 6, 2023
5 checks passed
Julow added a commit to Julow/opam-repository that referenced this pull request Dec 11, 2023
CHANGES:

### Added

- Add support for external search engines (@panglesd, @EmileTrotignon, ocaml/odoc#972)
  This includes the generation of an index and the display of the results in
  the UI (HTML only).

- Display 'private' keyword for private type extensions (@gpetiot, ocaml/odoc#1019)
- Allow to omit parent type in constructor reference (@panglesd,
  @EmileTrotignon, ocaml/odoc#933)

### Fixed

- Warn and exit when table(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Hint when list(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Fix crash on functors returning an alias (@Julow, ocaml/odoc#1046)
- Fix rendering of polymorphic variants (@wikku, @panglesd, ocaml/odoc#971)
- Add references to extension declarations (@gpetiot, @panglesd, ocaml/odoc#949)

### Changed

- Style: Adjusted line height in the TOC to improve readability (@sorawee, ocaml/odoc#1045)
- Style: Remove font fallback to Helvetica, Arial (@Julow, ocaml/odoc#1028)
- Style: Preformatted elements fallback to UA monospace (@toastal, ocaml/odoc#967)
- Style: Sidebar is now stuck to the left of the content instead of the left of
  the viewport (@EmileTrotignon, ocaml/odoc#999)
Julow added a commit to Julow/opam-repository that referenced this pull request Dec 12, 2023
CHANGES:

### Added

- Add support for external search engines (@panglesd, @EmileTrotignon, ocaml/odoc#972)
  This includes the generation of an index and the display of the results in
  the UI (HTML only).

- Display 'private' keyword for private type extensions (@gpetiot, ocaml/odoc#1019)
- Allow to omit parent type in constructor reference (@panglesd,
  @EmileTrotignon, ocaml/odoc#933)

### Fixed

- Warn and exit when table(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Hint when list(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Fix crash on functors returning an alias (@Julow, ocaml/odoc#1046)
- Fix rendering of polymorphic variants (@wikku, @panglesd, ocaml/odoc#971)
- Add references to extension declarations (@gpetiot, @panglesd, ocaml/odoc#949)

### Changed

- Style: Adjusted line height in the TOC to improve readability (@sorawee, ocaml/odoc#1045)
- Style: Remove font fallback to Helvetica, Arial (@Julow, ocaml/odoc#1028)
- Style: Preformatted elements fallback to UA monospace (@toastal, ocaml/odoc#967)
- Style: Sidebar is now stuck to the left of the content instead of the left of
  the viewport (@EmileTrotignon, ocaml/odoc#999)
Julow added a commit to Julow/opam-repository that referenced this pull request Dec 12, 2023
CHANGES:

### Added

- Add support for external search engines (@panglesd, @EmileTrotignon, ocaml/odoc#972)
  This includes the generation of an index and the display of the results in
  the UI (HTML only).

- Display 'private' keyword for private type extensions (@gpetiot, ocaml/odoc#1019)
- Allow to omit parent type in constructor reference (@panglesd,
  @EmileTrotignon, ocaml/odoc#933)

### Fixed

- Warn and exit when table(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Hint when list(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Fix crash on functors returning an alias (@Julow, ocaml/odoc#1046)
- Fix rendering of polymorphic variants (@wikku, @panglesd, ocaml/odoc#971)
- Add references to extension declarations (@gpetiot, @panglesd, ocaml/odoc#949)

### Changed

- Style: Adjusted line height in the TOC to improve readability (@sorawee, ocaml/odoc#1045)
- Style: Remove font fallback to Helvetica, Arial (@Julow, ocaml/odoc#1028)
- Style: Preformatted elements fallback to UA monospace (@toastal, ocaml/odoc#967)
- Style: Sidebar is now stuck to the left of the content instead of the left of
  the viewport (@EmileTrotignon, ocaml/odoc#999)
Julow added a commit to Julow/opam-repository that referenced this pull request Dec 12, 2023
CHANGES:

### Added

- Add support for external search engines (@panglesd, @EmileTrotignon, ocaml/odoc#972)
  This includes the generation of an index and the display of the results in
  the UI (HTML only).

- Display 'private' keyword for private type extensions (@gpetiot, ocaml/odoc#1019)
- Allow to omit parent type in constructor reference (@panglesd,
  @EmileTrotignon, ocaml/odoc#933)

### Fixed

- Warn and exit when table(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Hint when list(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Fix crash on functors returning an alias (@Julow, ocaml/odoc#1046)
- Fix rendering of polymorphic variants (@wikku, @panglesd, ocaml/odoc#971)
- Add references to extension declarations (@gpetiot, @panglesd, ocaml/odoc#949)

### Changed

- Style: Adjusted line height in the TOC to improve readability (@sorawee, ocaml/odoc#1045)
- Style: Remove font fallback to Helvetica, Arial (@Julow, ocaml/odoc#1028)
- Style: Preformatted elements fallback to UA monospace (@toastal, ocaml/odoc#967)
- Style: Sidebar is now stuck to the left of the content instead of the left of
  the viewport (@EmileTrotignon, ocaml/odoc#999)
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

### Added

- Add support for external search engines (@panglesd, @EmileTrotignon, ocaml/odoc#972)
  This includes the generation of an index and the display of the results in
  the UI (HTML only).

- Display 'private' keyword for private type extensions (@gpetiot, ocaml/odoc#1019)
- Allow to omit parent type in constructor reference (@panglesd,
  @EmileTrotignon, ocaml/odoc#933)

### Fixed

- Warn and exit when table(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Hint when list(s) is not closed (@lubegasimon, ocaml/odoc#1050)
- Fix crash on functors returning an alias (@Julow, ocaml/odoc#1046)
- Fix rendering of polymorphic variants (@wikku, @panglesd, ocaml/odoc#971)
- Add references to extension declarations (@gpetiot, @panglesd, ocaml/odoc#949)

### Changed

- Style: Adjusted line height in the TOC to improve readability (@sorawee, ocaml/odoc#1045)
- Style: Remove font fallback to Helvetica, Arial (@Julow, ocaml/odoc#1028)
- Style: Preformatted elements fallback to UA monospace (@toastal, ocaml/odoc#967)
- Style: Sidebar is now stuck to the left of the content instead of the left of
  the viewport (@EmileTrotignon, ocaml/odoc#999)
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.

Reference to constructor in module
4 participants