Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#9177 closed feature request (fixed)

Suggest Int when user uses int

Reported by: nomeata Owned by: nomeata
Priority: normal Milestone: 7.10.1
Component: Compiler Version: 7.8.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #1388 Differential Rev(s):
Wiki Page:

Description

This ticket is a fork of #1388. We already give suggestions when the user mispells names, based on edit distance. But this does not cross the boundaries between different kind of names.

It would be helpful if Not in scope: type variable `int' would also say Did you mean the type constructor `Int'?

Change History (11)

comment:1 Changed 2 years ago by simonpj

Good idea. Want to implement it?

Simon

comment:2 Changed 2 years ago by nomeata

  • Owner set to nomeata

Almost done, this is my ZuriHac2014 warm up ticket :-)

Last edited 2 years ago by nomeata (previous) (diff)

comment:3 follow-up: Changed 2 years ago by nomeata

I have two variants: One that suggests Integer when integer is typed, and one that suggests even Integer if integerr is typed (using the same edit distance metric stuff). I’ll push the first, followed by the second, so that one can easily revert.

Of course there is no limit on how smart the error message can be. In type Foo = eq, one cannot mean Eq (as it is a class), but that is not available on the level of OccNames. But I guess the suggestion is still an improvement.

comment:4 Changed 2 years ago by nomeata

  • Status changed from new to patch

Another example of this logic leading the user into a direction that will cause a different error:

Prelude> let foo = ()
Prelude> let g = Foo  -- good suggestion

<interactive>:5:9:
    Not in scope: data constructor ‘Foo’
    Perhaps you meant variable ‘foo’ (line 2)
Prelude> let f (Foo x) = x  -- bad suggestion

<interactive>:3:8:
    Not in scope: data constructor ‘Foo’
    Perhaps you meant variable ‘foo’ (line 2)

Anyways, I pushed it to wip/T9177 for review (but will likely push to master in the next days; people can still complain afterwards).

comment:5 Changed 2 years ago by simonpj

Sounds good to me. Do get someone at Zurihac to look it over and then push to master.

Simon

comment:6 Changed 2 years ago by Joachim Breitner <mail@…>

In 009e86f5dd2bc2657be093c76ba679b7866b651a/ghc:

Suggest Int when user writes int

and the other way around. This fixes #9177.

comment:7 Changed 2 years ago by Joachim Breitner <mail@…>

In ae41a50f0378c00351df5414b35026fc4bce2b44/ghc:

Report all possible results from related name spaces

instead of just one matching directly. This is an alternative way to fix
ticket #9177.

comment:8 Changed 2 years ago by Joachim Breitner <mail@…>

In d3cae19055d6f148b6085fb5d6885a1826215aad/ghc:

Add testcase for #9177 and adjust test output

comment:9 Changed 2 years ago by nomeata

  • Resolution set to fixed
  • Status changed from patch to closed

comment:10 in reply to: ↑ 3 Changed 2 years ago by goldfire

Replying to nomeata:

I have two variants: One that suggests Integer when integer is typed, and one that suggests even Integer if integerr is typed (using the same edit distance metric stuff). I’ll push the first, followed by the second, so that one can easily revert.

Of course there is no limit on how smart the error message can be. In type Foo = eq, one cannot mean Eq (as it is a class), but that is not available on the level of OccNames. But I guess the suggestion is still an improvement.

In case anyone is inspired to make this smarter, I'll note that type Foo = Eq is perfectly reasonable, in the presence of ConstraintKinds.

comment:11 Changed 2 years ago by hvr

  • Milestone set to 7.10.1
Note: See TracTickets for help on using tickets.