Skip to content

Renaming in presence of type errors #3799

Closed
@coot

Description

@coot

Your environment

Which OS do you use?
Fedora
Which version of GHC do you use and how did you install it?
9.6.2 from ghcup
How is your project built (alternative: link to the project)?

Which LSP client (editor/plugin) do you use?
vim+coc.nvim
Which version of HLS do you use and how did you install it?

Have you configured HLS in any way (especially: a hie.yaml file)?
no

Steps to reproduce

Use the following file

module X where

data X a where
  X :: X Int
  Y :: X String
  Z :: X Int

a :: X Int
a = X

-- this doesn't type check on purpose:
instance Eq X where
  (==) = \_ _ -> True

Try to rename the X data type to X'.

Expected behaviour

Either nothing should be changed or everything even in presence of type errors.

Actual behaviour

module X where

data X a where
  X :: X Int
  Y :: X String
  Z :: X Int

a :: X Int
a = X

-- this doesn't type check on purpose:
instance Eq X' where
  (==) = \_ _ -> True

i.e. non of the X occurrences in the defintiion of X or a changed, only its occurrence in the Eq instance.

Debug information

Activity

added
type: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..
on Sep 10, 2023
fendor

fendor commented on Sep 10, 2023

@fendor
Collaborator

Hi, thank you for your bug report!

Likely, the rename handler uses useWithStale, causing it to fall back to the latest compiling file state.

I agree, renaming doesn't make sense if the module doesn't compile. I think, we should have two modi, for local renames only, we require that the module we look at compiles, for cross module renaming, the whole project needs to compile successfully.

This should be simple enough to fix in https://github.com/haskell/haskell-language-server/blob/master/plugins/hls-rename-plugin/src/Ide/Plugin/Rename.hs#L232. Instead of useWithStaleE, prefer useE.
Likely, we need something like getNamesAtPoint but without any PositionMapping.

added a commit that references this issue on Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: hls-rename-pluginlevel: easyThe issue is suited for beginnerstype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @coot@michaelpj@fendor

      Issue actions

        Renaming in presence of type errors · Issue #3799 · haskell/haskell-language-server