[GHC] #9930: By default, a source code would get overwritten by executable on *nix

#9930: By default, a source code would get overwritten by executable on *nix -------------------------------------+------------------------------------- Reporter: Rufflewind | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Other Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- If I have a source code without an extension, say `foo`, and I forget to specify the output file via `-o`, GHC will overwrite it with the executable itself after compilation. This occurs only on *nix-like operating systems. Presumably something similar could happen on Windows – fortunately, those who use `.exe` for source code are probably among the minority. Minimum example: {{{#!sh #!/bin/sh echo >foo 'main=undefined' ghc -x hs foo less foo # 'foo' now contains binary data }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9930 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9930: By default, a source code without extension would get overwritten by executable on *nix -------------------------------------+------------------------------------- Reporter: Rufflewind | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9930#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9930: By default, a source code without extension would get overwritten by executable on *nix -------------------------------------+------------------------------------- Reporter: Rufflewind | Owner: Rufflewind Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by Rufflewind): * owner: => Rufflewind -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9930#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9930: By default, a source code without extension would get overwritten by executable on *nix -------------------------------------+------------------------------------- Reporter: Rufflewind | Owner: Rufflewind Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): I would suggest that `-o` be required when the source filename does not have the expected file extension for its language (as specified by `-x`). I'd greatly prefer that to GHC trying to guess whether the user really meant to do what they asked GHC to do. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9930#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9930: By default, a source code without extension would get overwritten by executable on *nix -------------------------------------+------------------------------------- Reporter: Rufflewind | Owner: Rufflewind Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by Rufflewind): Replying to [comment:3 rwbarton]:
I would suggest that `-o` be required when the source filename does not have the expected file extension for its language (as specified by `-x`).
I was thinking of failing with an error only if `-o` is not provided and the input and output filenames would coincide. It's a bit less restrictive than your suggestion and should cover the typical cases where this occurs. What do you think? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9930#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9930: By default, a source code without extension would get overwritten by
executable on *nix
-------------------------------------+-------------------------------------
Reporter: Rufflewind | Owner: Rufflewind
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.4
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Other | Unknown/Multiple
Blocked By: | Test Case:
Related Tickets: | Blocking:
| Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#9930: By default, a source code without extension would get overwritten by executable on *nix -------------------------------------+------------------------------------- Reporter: Rufflewind | Owner: Rufflewind Type: bug | Status: merge Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: new => merge * milestone: => 7.10.1 Comment: Merged, thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9930#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9930: By default, a source code without extension would get overwritten by executable on *nix -------------------------------------+------------------------------------- Reporter: Rufflewind | Owner: Rufflewind Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.4 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed Comment: Merged to `ghc-7.10` (via ed4de443b31bc383cc7194bef75d27c3a487e8de). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9930#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9930: By default, a source code without extension would get overwritten by
executable on *nix
-------------------------------------+-------------------------------------
Reporter: Rufflewind | Owner: Rufflewind
Type: bug | Status: closed
Priority: normal | Milestone: 7.10.1
Component: Compiler | Version: 7.8.4
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Other | Unknown/Multiple
Blocked By: | Test Case:
Related Tickets: | Blocking:
| Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang
participants (1)
-
GHC