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

Fix: Inconsistent type vars in "unbound type var" message #11194

Closed
wants to merge 4 commits into from

Conversation

voodoos
Copy link
Contributor

@voodoos voodoos commented Apr 15, 2022

When upgrading Merlin for 4.14 our test-suite catched the following issue:

class test a c =
object
  method b = c
end

[%%expect{|
Lines 1-4, characters 0-3:
1 | class test a c =
2 | object
3 |   method b = c
4 | end
Error: Some type variables are unbound in this type:
         class test : 'a -> 'b -> object method b : 'b end
       The method b has type 'a where 'a is unbound
|}]

In this example the printed type for method b is inconsistent.
This is due to an extraneous reset of the printer introduced in #10488

This PR add a test illustrating the issue and a fix proposition.

The type var should stay coherent in a same error message. This is not the case for "variables unbound" messages.
@voodoos voodoos changed the title Inconsistent type vars in "unbound type var" message Fix: Inconsistent type vars in "unbound type var" message Apr 29, 2022
@voodoos
Copy link
Contributor Author

voodoos commented Jun 22, 2022

Hi @Octachron not sure if you are the correct person to ping, sorry if that is not the case :-)
This PR is a very small fix to the printing of some errors, I guess it should be fairly fast to review.
(I can rebase if needed)

@Octachron Octachron self-assigned this Jun 22, 2022
@Octachron
Copy link
Member

Thanks for the reminder! I have added the PR to my review stack for next week.

let ty1 =
if real then ty0 else Btype.newgenty(Tobject(ty0, ref None))
in
Printtyp.prepare_for_printing [ty; ty1];
Copy link
Member

@Octachron Octachron Jun 27, 2022

Choose a reason for hiding this comment

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

Moving this preparation here makes it a no-op: printer is either Printtyp.class_declaration or Printtyp.cltype_declaration and both of them call Printtyp.reset_context undoing the work done by this call.
Moreover, this matters because there is at least one case where Printtyp.class_declaration does not print itself the method type and thus may not mark cycles which may lead to a stack overflow in the printer(with this PR):

class ['a] c = object method m: (<x:'a; f:'b> as 'b) -> unit = fun _ -> () end
class d = ['a] c

Copy link
Member

Choose a reason for hiding this comment

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

With the way that the printing classes are wired, I fear that the easiest solution would be to add an optional ?(reset=true) argument to Printtyp.prepare_for_printing and use it in the suberror message printer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, thanks for your review and these insights, I will give it more thoughts.

@Octachron
Copy link
Member

@voodoos : did you have the time to work on this PR? If not would you mind if I submitted my version of the fix?

@voodoos
Copy link
Contributor Author

voodoos commented Oct 5, 2022

I didn't sadly. Feel free to close this and propose your own :-)

Octachron added a commit that referenced this pull request Oct 17, 2022
…_context

#11194: fix an inconsistency in type variable names in error messages
@Octachron
Copy link
Member

Superseded by #11609 .

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.

None yet

2 participants