@@ -18,7 +18,7 @@ import Agda.Utils.Impossible ( __IMPOSSIBLE__ )
1818import Agda2Hs.AgdaUtils
1919
2020import Agda2Hs.Compile.Name
21- import Agda2Hs.Compile.Type ( compileDomType , compileTeleBinds )
21+ import Agda2Hs.Compile.Type ( compileDomType , compileTeleBinds , compileDom , DomOutput ( .. ) )
2222import Agda2Hs.Compile.Types
2323import Agda2Hs.Compile.Utils
2424
@@ -116,7 +116,7 @@ checkCompileToDataPragma def s = noCheckNames $ do
116116 rpars <- compileTeleBinds True rtel
117117 unless (length rpars == length dpars) $ fail
118118 " they have a different number of parameters"
119- forM (zip dpars rpars) $ \ (Hs. KindedVar _ a ak, Hs. KindedVar _ b bk) ->
119+ forM_ (zip dpars rpars) $ \ (Hs. KindedVar _ a ak, Hs. KindedVar _ b bk) ->
120120 unless (ak == bk) $ fail $
121121 " parameter" <+> text (Hs. pp a) <+> " of kind" <+> text (Hs. pp ak) <+>
122122 " does not match" <+> text (Hs. pp b) <+> " of kind" <+> text (Hs. pp bk)
@@ -132,16 +132,47 @@ checkCompileToDataPragma def s = noCheckNames $ do
132132 forM_ (zip dcons rcons) $ \ (c1, c2) -> do
133133 Hs. QualConDecl _ _ _ (Hs. ConDecl _ hsC1 args1) <-
134134 addContext dtel $ compileConstructor (teleArgs dtel) c1
135+ -- rename parameters of r to match those of d
136+ rtel' <- renameParameters dtel rtel
135137 Hs. QualConDecl _ _ _ (Hs. ConDecl _ hsC2 args2) <-
136- addContext rtel $ compileConstructor (teleArgs rtel) c2
138+ addContext rtel' $ compileConstructor (teleArgs rtel' ) c2
137139 unless (hsC1 == hsC2) $ fail $
138140 " name of constructor" <+> text (Hs. pp hsC1) <+>
139141 " does not match" <+> text (Hs. pp hsC2)
140142 unless (length args1 == length args2) $ fail $
141143 " number of arguments to" <+> text (Hs. pp hsC1) <+>
142144 " does not match with" <+> text (Hs. pp hsC2)
143- forM (zip args1 args2) $ \ (b1, b2) ->
145+ forM_ (zip args1 args2) $ \ (b1, b2) ->
144146 unless (b1 == b2) $ fail $
145147 " constructor argument type" <+> text (Hs. pp b1) <+>
146148 " does not match with" <+> text (Hs. pp b2)
147149 addCompileToName c1 c2
150+
151+ where
152+ -- Use the names of the non-erased variables in the first telescope
153+ -- as the names of the non-erased variables in the second telescope.
154+ renameParameters :: Telescope -> Telescope -> C Telescope
155+ renameParameters tel1 tel2 = flip loop tel2 =<< nonErasedNames tel1
156+ where
157+ loop :: [ArgName ] -> Telescope -> C Telescope
158+ loop _ EmptyTel = pure EmptyTel
159+ loop [] tel = pure tel
160+ loop (x: xs) (ExtendTel dom tel) = compileDom dom >>= \ case
161+ DOType -> ExtendTel dom . Abs x <$>
162+ underAbstraction dom tel (loop xs)
163+ DODropped -> ExtendTel dom . Abs (absName tel) <$>
164+ underAbstraction dom tel (loop (x: xs))
165+ DOTerm -> __IMPOSSIBLE__
166+ DOInstance -> __IMPOSSIBLE__
167+
168+ nonErasedNames :: Telescope -> C [ArgName ]
169+ nonErasedNames EmptyTel = pure []
170+ nonErasedNames (ExtendTel dom tel) = do
171+ cd <- compileDom dom
172+ let mx = case cd of
173+ DOType -> (absName tel : )
174+ DODropped -> id
175+ DOTerm -> __IMPOSSIBLE__
176+ DOInstance -> __IMPOSSIBLE__
177+ mx <$> underAbstraction dom tel nonErasedNames
178+
0 commit comments