Skip to content

Exception when running compile-time code when using autogenerated cabal Paths_pkgname module in template haskell #4611

Open
@NeuroCorgi

Description

@NeuroCorgi

Which OS do you use?
MacOS
Which version of GHC do you use and how did you install it?
GHC 9.10.1 with ghcup
How is your project built (alternative: link to the project)?
cabal build
Which LSP client (editor/plugin) do you use?
emacs+eglot
Which version of HLS do you use and how did you install it?
haskell-language-server 2.9.0.1 with ghcup

Steps to reproduce

When using autogenerated Paths_<pkgname> module from Cabal to read project files from a template haskell function, HLS reports an error diagnostic at the splice sites that use this function.

Reproducing project

reproducing project

project.cabal

cabal-version:      3.0
name:               project
version:            0.1.0.0
license:            MIT
license-file:       LICENSE
author:             NeuroCorgi
build-type:         Simple

executable project
    main-is:          Main.hs
    other-modules:    TH
                      Paths_project
    autogen-modules:  Paths_project
    build-depends:    base, template-haskell
    hs-source-dirs:   src
    default-language: Haskell2010

src/Main.hs

{-# LANGUAGE TemplateHaskell #-}

import TH

main :: IO ()
main = putStrLn $(embedFileFromProject "src/TH.hs")

src/TH.hs

module TH where

import System.IO
import Language.Haskell.TH

import qualified Paths_project as Paths

embedFileFromProject :: FilePath -> ExpQ
embedFileFromProject filePath = stringE =<< (runIO $ contents =<< Paths.getDataFileName filePath)
  where contents path = withFile path ReadMode hGetContents'

Expected behaviour

No diagnostic reported.

Actual behaviour

Diagnostic reported at the template haskell splice in src/Main.hs:

• Exception when trying to run compile-time code:
    /Users/neurocorgi/.cabal/share/aarch64-osx-ghc-9.10.1-64dd/project-0.1.0.0/src/TH.hs: withFile: does not exist (No such file or directory)
  Code: (embedFileFromProject "src/TH.hs")
• In the untyped splice: $(embedFileFromProject "src/TH.hs")

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: ghcidetype: 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