Opened 4 years ago

Last modified 4 years ago

#11247 new bug

Weird error from running runghc on an invalid input filename

Reported by: rwbarton Owned by:
Priority: low Milestone:
Component: Compiler Version: 7.8.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case: runghc/T11247
Blocked By: Blocking:
Related Tickets: #7765 Differential Rev(s): Phab:D1678
Wiki Page:


I had files random.hs and random.hi and random.o, so I accidentally entered the following command with tab completion.

rwbarton@morphism:/tmp$ runghc random.
Warning: ignoring unrecognised input `random.'

    Not in scope: ‘main’
    Perhaps you meant ‘min’ (imported from Prelude)

#7765 is surely related, but with HEAD (well, rather old, but at least new enough to contain the fix for #7765), the error is not really any better:

rwbarton@morphism:/tmp$ ~/ghc/inplace/bin/runghc random.
Warning: ignoring unrecognised input `random.'

random.:0:53: error:
    Variable not in scope: main :: IO a0
    Perhaps you meant ‘min’ (imported from Prelude)

Change History (5)

comment:1 Changed 4 years ago by thomie

Differential Rev(s): Phab:D1678
Test Case: runghc/T11247

comment:2 Changed 4 years ago by thomie

Type of failure: None/UnknownIncorrect warning at compile-time

comment:3 Changed 4 years ago by thomie

Just putting down some notes here:

  • runghc random. calls ghc -e :main random.
  • The function function partition_args in ghc/Main.hs decides that random. doesn't look like a source file input.
  • So it becomes a linker input (ldInputs).
  • But then classifyLdInput in compiler/main/Linker.hs decides it isn't a suitable linker input either, and ignores it.

From 948e7f388748078a8d9a324b284da7c4029f7060:

In GHCi & Template Haskell, give a warning for things mentioned on the command line that we don't recognise, and then ignore them. In batch mode, these are still passed to the linker as before.

Indeed, ghc random. shows an error produced by the linker: gcc: error: random.: No such file or directory

comment:4 Changed 4 years ago by thomie

Some possible ways to solve this:

  • Throw an exception when classifyLdInput finds an unrecognised input. I wonder if this would break anything.
  • Or only throw an exception when the unrecognised input is a file that doesn't exist (passing an existing but invalid file would still be a warning).
  • Or check before putting files in ldInputs whether they exist. This affects normal ghc make and batch mode as well.

Do not:

  • modify runghc, since ghc -e :main has the same problem
  • only treat .o and .so files as linker inputs (failed attempt in Phab:D1678). Linker inputs can have any extension, for example .dyn_o.
Last edited 4 years ago by thomie (previous) (diff)

comment:5 Changed 4 years ago by Thomas Miedema <thomasmiedema@…>

In db97ed9/ghc:

Add (failing) test for #11247
Note: See TracTickets for help on using tickets.