From 1402b02268076ee3d35a576813ee09d72fe5c874 Mon Sep 17 00:00:00 2001
From: David Terry <me@xwvvvvwx.com>
Date: Thu, 7 Oct 2021 21:38:40 +0200
Subject: [PATCH] hevm: tty: skip null src maps when jumping with shift+n

---
 src/hevm/CHANGELOG.md   | 1 +
 src/hevm/src/EVM/TTY.hs | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/hevm/CHANGELOG.md b/src/hevm/CHANGELOG.md
index 11e13d3d3..048c00754 100644
--- a/src/hevm/CHANGELOG.md
+++ b/src/hevm/CHANGELOG.md
@@ -6,6 +6,7 @@
 
 - Test contracts with no code (e.g. `abstract` contracts) are now skipped
 - Replay data for invariant tests is now displayed in a form that does not cause errors when used with `dapp test --replay`
+- Stepping through the debugger with `shift + n` now always skips positions in the bytecode that do not have a corresponding position in the solidity source map
 
 ## [0.48.1] - 2021-09-08
 
diff --git a/src/hevm/src/EVM/TTY.hs b/src/hevm/src/EVM/TTY.hs
index a2397775f..e8272e36f 100644
--- a/src/hevm/src/EVM/TTY.hs
+++ b/src/hevm/src/EVM/TTY.hs
@@ -838,7 +838,12 @@ isNextSourcePosition
 isNextSourcePosition ui vm =
   let dapp' = dapp (view uiTestOpts ui)
       initialPosition = currentSrcMap dapp' (view uiVm ui)
-  in currentSrcMap dapp' vm /= initialPosition
+      currentPosition = currentSrcMap dapp' vm
+  in (not . isNullPosition $ currentPosition) && (currentPosition /= initialPosition)
+
+isNullPosition :: Maybe SrcMap -> Bool
+isNullPosition (Just (SM{..})) = srcMapOffset == -1 && srcMapLength == -1 && srcMapFile == -1
+isNullPosition Nothing = True
 
 isNextSourcePositionWithoutEntering
   :: UiVmState -> Pred VM