- rdr_env type_env expr)
- -- Coerce it to Q t, and run it
- ; TH.runQ (unsafeCoerce# hval) }
+ rdr_env type_env expr
+ ; case either_hval of {
+ Left exn -> failWithTc (mk_msg "compile and link" exn) ;
+ Right hval -> do
+
+ { -- Coerce it to Q t, and run it
+ -- Running might fail if it throws an exception of any kind (hence tryAllM)
+ -- including, say, a pattern-match exception in the code we are running
+ --
+ -- We also do the TH -> HS syntax conversion inside the same
+ -- exception-cacthing thing so that if there are any lurking
+ -- exceptions in the data structure returned by hval, we'll
+ -- encounter them inside the tryALlM
+ either_tval <- tryAllM $ do
+ { th_syn <- TH.runQ (unsafeCoerce# hval)
+ ; case convert (getLoc expr) th_syn of
+ Left err -> do { addErrTc err; return Nothing }
+ Right hs_syn -> return (Just hs_syn) }