Skip to content

Commit 32cfa5c

Browse files
committed
Add test for DebugView orphan instances
Seemingly, #237 is not about all orphan instances, but rather some slightly more contrived scenario that prevents us from using a `DebugView ModuleGraph` defined as an orphan in the debugger when debugging the debugger. This test checks that orphan instances in a normal situation work properly.
1 parent 8738761 commit 32cfa5c

6 files changed

Lines changed: 70 additions & 0 deletions

File tree

test/golden/T237/T237.cabal

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cabal-version: 3.14
2+
name: T237
3+
version: 0.1.0.0
4+
license: NONE
5+
author: Rodrigo Mesquita
6+
maintainer: rodrigo.m.mesquita@gmail.com
7+
build-type: Simple
8+
9+
common warnings
10+
ghc-options: -Wall
11+
12+
library
13+
import: warnings
14+
exposed-modules: MyType
15+
build-depends: base
16+
hs-source-dirs: lib
17+
default-language: Haskell2010
18+
19+
executable T237
20+
import: warnings
21+
main-is: Main.hs
22+
build-depends: base, T237, haskell-debugger-view
23+
hs-source-dirs: app
24+
default-language: Haskell2010
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[1 of 2] Compiling Main ( <TEMPORARY-DIRECTORY>/app/Main.hs, interpreted )[T237-0.1.0.0-inplace-T237]
2+
<TEMPORARY-DIRECTORY>/app/Main.hs:8:1: warning: [GHC-90177] [-Worphans]
3+
Orphan class instance: instance DebugView MyType
4+
Suggested fix:
5+
Move the instance declaration to the module of the class or of the type, or
6+
wrap the type with a newtype and declare the instance on the new type.
7+
 |
8+
8 | instance DebugView MyType where
9+
 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
10+
11+
(hdb) BreakFound {changed = True, breakId = [InternalBreakpointId Main 1], sourceSpan = SourceSpan {file = "<TEMPORARY-DIRECTORY>/app/Main.hs", startLine = 15, endLine = 15, startCol = 3, endCol = 28}}
12+
(hdb) Stopped at breakpoint
13+
(hdb) _result : IO () = <fn> :: IO ()
14+
value : MyType = _
15+
value : MyType = alpha:beta:gamma
16+
(hdb) Exiting...

test/golden/T237/T237.hdb-stdin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
break app/Main.hs 15
2+
run
3+
variables

test/golden/T237/T237.hdb-test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$HDB -v0 app/Main.hs 2>&1 < T237.hdb-stdin || true

test/golden/T237/app/Main.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Main (main) where
2+
3+
import Data.List (intercalate)
4+
5+
import GHC.Debugger.View.Class
6+
import MyType
7+
8+
instance DebugView MyType where
9+
debugValue (MyType xs) = simpleValue (intercalate ":" xs) False
10+
debugFields _ = pure (VarFields [])
11+
12+
main :: IO ()
13+
main = do
14+
let value = mkValue
15+
const (print value) value

test/golden/T237/lib/MyType.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module MyType
2+
( MyType(..)
3+
, mkValue
4+
) where
5+
6+
newtype MyType = MyType [String]
7+
deriving Show
8+
9+
mkValue :: MyType
10+
mkValue = MyType ["alpha", "beta", "gamma"]
11+
{-# OPAQUE mkValue #-}

0 commit comments

Comments
 (0)