Skip to content

Eval plugin uses language extensions of the caller in imported modules #2726

Open
@matpyz

Description

@matpyz

Your environment

Which OS do you use:
Ubuntu 20.04 LTS inside WSL 2 (Windows 10 21H2)
Which LSP client (editor/plugin) do you use:
VS Code + haskell extension, HLS 1.4 from Nixpkgs 21.11 running in nix-shell
Compiler:
GHC 8.10.7
Describe your project (alternative: link to the project):
Library-only cabal project with two files: lib/A.hs, lib/B.hs

Steps to reproduce

lib/A.hs:

module A where
foo :: Char -> Bool
foo c = c `elem` ['\\']

lib/B.hs:

{-# LANGUAGE OverloadedLists #-}
module B where
import A
import Data.Sequence
-- >>> foo <$> ['\\'] :: Seq Bool

Expected behaviour

Eval plugin should print:
-- fromList [True]

Actual behaviour

Pop-up window shows with the following message:

These modules are needed for compilation but not listed in your .cabal file's other-modules: 
    A B • Couldn't match expected type ‘GHC.Exts.Item (t0 Char)’
              with actual type ‘Char’
  The type variable ‘t0’ is ambiguous
• In the expression: '\\'
  In the second argument of ‘elem’, namely ‘['\\']’
  In the expression: c `elem` ['\\']

It appears to me that eval plugin tries to interpret modules with language pragmas inherited from the caller (B.hs) while it should respect pragmas of the callee (A.hs).
Workaround: type annotations in the callee to resolve ambiguity.
This is however very annoying for my real-world scenario, where callee module is generated by alex. This requires to manually patch auto-generated files in two places after each change in the lexer specification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: hls-eval-plugintype: 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

    Development

    No branches or pull requests

    Issue actions