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

location information in the typing error message could be made more precise #7315

Closed
vicuna opened this issue Aug 3, 2016 · 4 comments
Closed
Assignees

Comments

@vicuna
Copy link

vicuna commented Aug 3, 2016

Original bug ID: 7315
Reporter: kosik
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2017-09-24T15:33:19Z)
Resolution: fixed
Priority: low
Severity: tweak
Version: 4.03.0
Fixed in version: later
Category: typing
Monitored by: @gasche

Bug description

After typing:

type foo = (unit,unit,unit,unit,unit,unit) bar;;

Ocaml (correctly) reports that:

Error: Unbound type constructor bar

What I do not understand is why the location information is so vague.
Currently Ocaml pin-points the problem to:

"(unit,unit,unit,unit,unit,unit) bar"

Why doesn't it provide a more precise location, i.e. where

"bar"

identifier actually occurs?

Steps to reproduce

echo 'type foo = (unit,unit,unit,unit,unit,unit) bar;;' | ocaml

@vicuna
Copy link
Author

vicuna commented Aug 3, 2016

Comment author: @gasche

This particular imprecision is fixed by the following one-line change:

diff --git a/typing/typetexp.ml b/typing/typetexp.ml
index e0d06dd..ccc760a 100644
--- a/typing/typetexp.ml
+++ b/typing/typetexp.ml
@@ -340,7 +340,7 @@ let rec transl_type env policy styp =
let ty = newty (Ttuple (List.map (fun ctyp -> ctyp.ctyp_type) ctys)) in
ctyp (Ttyp_tuple ctys) ty
| Ptyp_constr(lid, stl) ->

  •  let (path, decl) = find_type env styp.ptyp_loc lid.txt in
    
  •  let (path, decl) = find_type env lid.loc lid.txt in
     let stl =
       match stl with
       | [ {ptyp_desc=Ptyp_any} as t ] when decl.type_arity > 1 ->
    

What are other error messages whose location should be similarly refined?

@vicuna
Copy link
Author

vicuna commented Aug 3, 2016

Comment author: kosik

I do not know about other scenarios in which Ocaml compiler produces unnecessarily vague location information. I can promise to report them once I spot them.

However, if Merlin has a separate typechecking engine from Ocaml compiler, it may also make sense to fix it in a similar way, because it behaves consistently (imprecisely) with the Ocaml compiler.

@vicuna
Copy link
Author

vicuna commented Aug 3, 2016

Comment author: @gasche

Proposed fix in
#736

@vicuna
Copy link
Author

vicuna commented Aug 4, 2016

Comment author: @gasche

Fixed in trunk. Thanks for the enhancement proposal!

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

No branches or pull requests

2 participants