@@ -630,7 +630,14 @@ elab ist info pattern opts fn tm
630630 elab' ina t
631631 unifyLog False
632632 elab' ina (PQuasiquote t)
633− = do -- Establish holes for the type and value of the term to be quasiquoted
633+ = do -- Save the old state - we need a fresh proof state for this to
634+ -- avoid capture
635+ ctxt <- get_context
636+ saveState
637+ updatePS (const $ newProof (sMN 0 "q") ctxt (P Ref (sNS (sUN "TT") ["Reflection", "Language"]) Erased))
638+
639+ -- Establish holes for the type and value of the term to be
640+ -- quasiquoted
634641 qTy <- getNameFrom (sMN 0 "qquoteTy")
635642 claim qTy RType
636643 qTm <- getNameFrom (sMN 0 "qquoteTm")
@@ -644,12 +651,16 @@ elab ist info pattern opts fn tm
644651 -- Elaborate the quasiquoted term into the hole that was
645652 focus qTm
646653 elab' ina t
647− -- We now have an elaborated term. Reflect it and solve the original goal
648− ctxt <- get_context
654+ -- We now have an elaborated term. Reflect it and solve the
655+ -- original goal
649656 env <- get_env
650− let qTerm = normalise ctxt env (P Bound nTm Erased)
651− fill $ reflect qTerm
652− solve
657+ let qTerm = fmap (reflect . binderVal) $ lookup nTm env
658+ case qTerm of
659+ Just q -> do loadState
660+ fill q
661+ solve
662+ Nothing -> fail "Broken elaboration of quasiquote"
663+
653664 elab' ina (PUnquote t) = fail "Elaboration of unquotes not yet implemented"
654665 elab' ina x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
655666