diff --git a/testsuite/tests/simplCore/should_run/T21229.hs b/testsuite/tests/simplCore/should_run/T21229.hs
new file mode 100644
index 0000000000000000000000000000000000000000..c5e22f677386e62d557bb625b46f1a9b05c98914
--- /dev/null
+++ b/testsuite/tests/simplCore/should_run/T21229.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE AllowAmbiguousTypes #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE KindSignatures #-}
+module Main where
+
+data B = T | F deriving Show
+
+class Sing (b :: B) where sing :: B
+instance Sing 'T where sing = T
+instance Sing 'F where sing = F
+
+f :: forall a. Sing a => Int -> (Int -> B -> B) -> B
+f 0 g = g 0 (sing @a)
+f n g = f @a (n-1) g
+
+h :: forall a. Sing a => Int -> (Int -> B -> B) -> B
+h = case sing @a of
+      T -> f @'T
+      F -> f @a
+{-# NOINLINE h #-}
+
+main = print $ h @'T 0 (\ _ a -> a)
diff --git a/testsuite/tests/simplCore/should_run/T21229.stdout b/testsuite/tests/simplCore/should_run/T21229.stdout
new file mode 100644
index 0000000000000000000000000000000000000000..62a6e3c9dfcb5f2a009cb85d9562145c1ea803a1
--- /dev/null
+++ b/testsuite/tests/simplCore/should_run/T21229.stdout
@@ -0,0 +1 @@
+T
diff --git a/testsuite/tests/simplCore/should_run/all.T b/testsuite/tests/simplCore/should_run/all.T
index 54ec5b8bff7f7321ffe9dfa7b13bd918d548ed5a..34e7e2e386d28762ca87c2ea42afae35185851aa 100644
--- a/testsuite/tests/simplCore/should_run/all.T
+++ b/testsuite/tests/simplCore/should_run/all.T
@@ -101,3 +101,4 @@ test('T19569', [only_ways(['optasm']),extra_run_opts('True 1000000')], compile_a
 test('T20203', normal, compile, ['-O -dsuppress-all -dsuppress-uniques -dno-typeable-binds -ddump-simpl'])
 test('T19313', normal, compile_and_run, [''])
 test('UnliftedArgRule', normal, compile_and_run, [''])
+test('T21229', normal, compile_and_run, ['-O'])