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

PR#7315: refine some error locations #736

Merged
merged 1 commit into from
Aug 4, 2016

Conversation

gasche
Copy link
Member

@gasche gasche commented Aug 3, 2016

Fixes MPR#7315 and some related imprecise messages -- I suspect that more remain, and started building a testsuite.

@alainfrisch
Copy link
Contributor

Ah, I was also working on it.

trunk...alainfrisch:better_loc_unbound_constructor

I'd propose to change the interface of Typetexp.find_type (and then other Typetexp.find_* functions as well) to take a longident Location.loc instead of two separate arguments. This encourage proper use on the call site, passing the exact location corresponding to the item being looked up. This would catch, for instance, the weird location on:

# type exn += X = Y;;
Characters 12-17:
  type exn += X = Y;;
              ^^^^^
Error: Unbound constructor Y

@gasche
Copy link
Member Author

gasche commented Aug 3, 2016

That sounds like a good idea. Feel free to integrate my tests, add some, and send a pull-request with your implementation.

@alainfrisch
Copy link
Contributor

alainfrisch commented Aug 3, 2016

I'm not sure I'll have time to finalize that quickly, so it's perhaps better to merge this PR and keep the API change in mind for later.

Do you think the two failing tests are related to this PR?

    tests/typing-misc/polyvars.ml
    tests/typing-objects/pr6383.ml.reference

@gasche
Copy link
Member Author

gasche commented Aug 3, 2016

Yes, the tests were related to changed location information. I fixed the tests and integrated your own changes to extension redefinitions (plus lookup of the extensible type's name). I'll wait to leave some opportunity for review, then merge in trunk. Thanks for the advice!

@@ -9,12 +9,12 @@ Error: This pattern matches values of type [? `A | `B ]
|}];;
let f x = ignore (match x with #ab -> 1); ignore (x : [`A]);;
[%%expect{|
Line _, characters 31-34:
Line _, characters 32-34:
Copy link
Contributor

Choose a reason for hiding this comment

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

One could argue that the pattern here is #ab, not ab, so the old location might be better.

let f (x: #M.foo) = 0;;
^^^^^^
^^^^^
Copy link
Member Author

@gasche gasche Aug 3, 2016

Choose a reason for hiding this comment

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

Note: it's not possible to refine the location here to M only without adding more location information inside Longident.t, which would result in a painful change to the interface used by everyone manipulating the parsetree -- not a good idea.

@ghost
Copy link

ghost commented Aug 4, 2016

The original behavior:

# type foo = (unit,unit,unit,unit) bar;;
Error: Unbound type constructor bar
# type foo = unit bar;;
Error: Unbound type constructor bar

The new behavior:

# type foo = (unit,unit,unit,unit) bar;;
Error: Unbound type constructor bar
# type foo = unit bar;;
Error: Unbound type constructor bar

It is not a big thing, but nevertheless a strict improvement, in my opinion.

@alainfrisch alainfrisch merged commit 4aef4ce into ocaml:trunk Aug 4, 2016
shindere pushed a commit to shindere/ocaml that referenced this pull request Aug 11, 2016
camlspotter pushed a commit to camlspotter/ocaml that referenced this pull request Oct 17, 2017
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Sep 21, 2022
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Co-authored-by: Jonah Beckford <9566106-jonahbeckford@users.noreply.gitlab.com>
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