Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
MPR7565 bis: more context for universal variable in error messages #2140
This PR is a follow-up of #1212, it proposes to give more context for universal type variables that escape their scope when unifying methods, by precising the actual type and expected type at the method level, as suggested by @garrigue in #1212 .
For instance, the following code
type uv = [ `A of <f: 'a. 'a -> int > ] type 'a v = [ `A of <f: 'a -> int > ] let f (`A o:uv) = o # f 0 let () = f ( `A (object method f _ = 0 end): _ v)
currently raises an error message
where the universal variable is mysteriously introduced on the last line (and is slightly renamed compared to the original type abbreviation ).
This PR adds a new line to this error message in order to introduce the universal variable:
In the current implementation, this line is added whenever a universal variable introduced by a method escape its field. This can lead to quite redundant error messages like
However, this behavior seemed mostly harmless and it could be avoided with further tuning.
Armael left a comment •
I will do a review later, but for the moment I have a question: can you explain a bit what
Also, could you clarify whether the new implementation of
In short, I have split the previous
In this situation, connecting the escaping universal variable with its parent method required to wade through those discarded trace elements:
Armael left a comment
I have no strong opinion on the general design, but it seems to produce better or equally good error messages, with a tolerable overhead.
Regarding the implementation, modulo the comments below, it looks equivalent to the existing one to me. I'm however not very fond of the increased amount of code manipulating traces that looks like its doing something very tricky, and that I have to read 10 times before figuring out it's actually doing something fairly simple.
(its possible that there is no nice solution without doing more global changes; in that case I'm fine with merging the PR as-is. I'm not very familiar with the overall logic of the file, and the code around doesn't look particularly nice anyway, so...)