Commit 802b5e6f authored by Krzysztof Gogolewski's avatar Krzysztof Gogolewski Committed by Marge Bot
Browse files

Fix linear types in TH splices (#18465)

parent bc5de347
......@@ -192,6 +192,8 @@ tcTypedBracket rn_expr brack@(TExpBr _ expr) res_ty
-- Throw away the typechecked expression but return its type.
-- We'll typecheck it again when we splice it in somewhere
; (_tc_expr, expr_ty) <- setStage (Brack cur_stage (TcPending ps_ref lie_var wrapper)) $
tcScalingUsage Many $
-- Scale by Many, TH lifting is currently nonlinear (#18465)
tcInferRhoNC expr
-- NC for no context; tcBracket does that
; let rep = getRuntimeRep expr_ty
......@@ -289,7 +291,8 @@ tcPendingSplice m_var (PendingRnSplice flavour splice_name expr)
= do { meta_ty <- tcMetaTy meta_ty_name
-- Expected type of splice, e.g. m Exp
; let expected_type = mkAppTy m_var meta_ty
; expr' <- tcCheckPolyExpr expr expected_type
; expr' <- tcScalingUsage Many $ tcCheckPolyExpr expr expected_type
-- Scale by Many, TH lifting is currently nonlinear (#18465)
; return (PendingTcSplice splice_name expr') }
where
meta_ty_name = case flavour of
......
{-# LANGUAGE TemplateHaskellQuotes, LinearTypes #-}
module LinearTHFail where -- #18465
import Language.Haskell.TH
f :: Q Exp %1 -> Q Exp
f x = [| Just $x |]
g :: Code Q a %1 -> Code Q (Maybe a)
g x = [|| Just $$x ||]
LinearTHFail.hs:8:3: error:
• Couldn't match type ‘'Many’ with ‘'One’
arising from multiplicity of ‘x’
• In an equation for ‘f’:
f x
= [| Just $x |]
pending(rn) [<splice, x>]
LinearTHFail.hs:11:3: error:
• Couldn't match type ‘'Many’ with ‘'One’
arising from multiplicity of ‘x’
• In an equation for ‘g’: g x = [|| Just $$x ||]
......@@ -30,3 +30,4 @@ test('LinearSequenceExpr', normal, compile_fail, [''])
test('LinearIf', normal, compile_fail, [''])
test('LinearPatternGuardWildcard', normal, compile_fail, [''])
test('LinearFFI', normal, compile_fail, [''])
test('LinearTHFail', normal, compile_fail, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment