@@ -136,11 +136,11 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
136 (cty, ty, inacc) <- buildType info syn fc opts n ty'
136 (cty, ty, inacc) <- buildType info syn fc opts n ty'
138 addStatics n cty ty
138 addStatics n cty ty
139− logLvl 2 $ "Rechecked to " ++ show cty
140 let nty = cty -- normalise ctxt [] cty
139 let nty = cty -- normalise ctxt [] cty
141 -- if the return type is something coinductive, freeze the definition
140 -- if the return type is something coinductive, freeze the definition
142 ctxt <- getContext
141 ctxt <- getContext
143 let nty' = normalise ctxt [] nty
142 let nty' = normalise ctxt [] nty
143+ logLvl 2 $ "Rechecked to " ++ show nty'
145 -- Add normalised type to internals
145 -- Add normalised type to internals
146 i <- getIState
146 i <- getIState
@@ -863,14 +863,18 @@ elabRecord info syn doc fc tyn ty opts cdoc cn cty_in
863 _ -> ifail "Something went inexplicably wrong"
863 _ -> ifail "Something went inexplicably wrong"
864 cimp <- case lookupCtxt cn (idris_implicits i) of
864 cimp <- case lookupCtxt cn (idris_implicits i) of
865 [imps] -> return imps
865 [imps] -> return imps
866+ ppos <- case lookupCtxt tyn (idris_datatypes i) of
867+ [ti] -> return $ param_pos ti
866− let ptys = getProjs [] (renameBs cimp cty)
868+ let cty_imp = renameBs cimp cty
869+ let ptys = getProjs [] cty_imp
867 let ptys_u = getProjs [] cty
870 let ptys_u = getProjs [] cty
868− let recty = getRecTy cty
871+ let recty = getRecTy cty_imp
872+ let recty_u = getRecTy cty
870 -- rename indices when we generate the getter/setter types, so
874 -- rename indices when we generate the getter/setter types, so
871 -- that they don't clash with the names of the projections
875 -- that they don't clash with the names of the projections
872 -- we're generating
876 -- we're generating
873− let index_names_in = getRecNameMap "_in" recty
877+ let index_names_in = getRecNameMap "_in" ppos recty
874 let recty_in = substMatches index_names_in recty
878 let recty_in = substMatches index_names_in recty
876 logLvl 1 $ show (recty, ptys)
880 logLvl 1 $ show (recty, ptys)
@@ -884,7 +888,7 @@ elabRecord info syn doc fc tyn ty opts cdoc cn cty_in
884 let implBinds = getImplB id cty'
888 let implBinds = getImplB id cty'
886 -- Generate update functions
890 -- Generate update functions
887− update_decls <- mapM (mkUpdate recty index_names_in extraImpls
891+ update_decls <- mapM (mkUpdate recty_u index_names_in extraImpls
888 (getFieldNames cty')
892 (getFieldNames cty')
889 implBinds (length nonImp)) (zip nonImp [0..])
893 implBinds (length nonImp)) (zip nonImp [0..])
890 mapM_ (elabDecl EAll info) (concat proj_decls)
894 mapM_ (elabDecl EAll info) (concat proj_decls)
@@ -932,15 +936,21 @@ elabRecord info syn doc fc tyn ty opts cdoc cn cty_in
932 getRecTy (PPi _ n ty s) = getRecTy s
936 getRecTy (PPi _ n ty s) = getRecTy s
933 getRecTy t = t
937 getRecTy t = t
939+ -- make sure we pick a consistent name for parameters; any name will do
935− getRecNameMap x (PApp fc t args) = mapMaybe (toMN . getTm) args
941+ getRecNameMap x ppos (PApp fc t args)
942+ = mapMaybe toMN (zip [0..] (map getTm args))
945+ | i `elem` ppos = Just (n, PRef fc (mkp n))
937− toMN (PRef fc n) = Just (n, PRef fc (sMN 0 (show n ++ x)))
946+ | otherwise = Just (n, PRef fc (sMN 0 (show n ++ x)))
938 toMN _ = Nothing
947 toMN _ = Nothing
939− getRecNameMap x _ = []
948+ getRecNameMap x _ _ = []
941 rec = sMN 0 "rec"
950 rec = sMN 0 "rec"
952+ -- only UNs propagate properly as parameters (bit of a hack then...)
943− mkp (UN n) = sMN 0 ("p_" ++ str n)
953+ mkp (UN n) = sUN ("_p_" ++ str n)
944 mkp (MN i n) = sMN i ("p_" ++ str n)
954 mkp (MN i n) = sMN i ("p_" ++ str n)
945 mkp (NS n s) = NS (mkp n) s
955 mkp (NS n s) = NS (mkp n) s
@@ -953,18 +963,19 @@ elabRecord info syn doc fc tyn ty opts cdoc cn cty_in
953 mkType (NS n s) = NS (mkType n) s
963 mkType (NS n s) = NS (mkType n) s
955 mkProj recty substs cimp ((pn_in, pty), pos)
965 mkProj recty substs cimp ((pn_in, pty), pos)
956− = do let pn = expandNS syn pn_in
966+ = do let pn = expandNS syn pn_in -- projection name
967+ -- use pn_in in the indices, consistently, to avoid clash
957 let pfnTy = PTy emptyDocstring [] defaultSyntax fc [] pn
968 let pfnTy = PTy emptyDocstring [] defaultSyntax fc [] pn
958 (PPi expl rec recty
969 (PPi expl rec recty
959 (substMatches substs pty))
970 (substMatches substs pty))
960 let pls = repeat Placeholder
971 let pls = repeat Placeholder
961 let before = pos
972 let before = pos
962 let after = length substs - (pos + 1)
973 let after = length substs - (pos + 1)
963− let args = take before pls ++ PRef fc (mkp pn) : take after pls
974+ let args = take before pls ++ PRef fc (mkp pn_in) : take after pls
964 let iargs = map implicitise (zip cimp args)
975 let iargs = map implicitise (zip cimp args)
965 let lhs = PApp fc (PRef fc pn)
976 let lhs = PApp fc (PRef fc pn)
966 [pexp (PApp fc (PRef fc cn) iargs)]
977 [pexp (PApp fc (PRef fc cn) iargs)]
967− let rhs = PRef fc (mkp pn)
978+ let rhs = PRef fc (mkp pn_in)
968 let pclause = PClause fc pn lhs [] rhs []
979 let pclause = PClause fc pn lhs [] rhs []
969 return [pfnTy, PClauses fc [] pn [pclause]]
980 return [pfnTy, PClauses fc [] pn [pclause]]
@@ -1425,7 +1436,8 @@ checkPossible info fc tcgen fname lhs_in
1425 | otherwise = False -- name is different, unrecoverable
1436 | otherwise = False -- name is different, unrecoverable
1427getFixedInType i env (PExp _ _ _ _ : is) (Bind n (Pi t) sc)
1438getFixedInType i env (PExp _ _ _ _ : is) (Bind n (Pi t) sc)
1439+ = nub $ getFixedInType i env [] t ++
1428− = getFixedInType i (n : env) is (instantiate (P Bound n t) sc)
1440+ getFixedInType i (n : env) is (instantiate (P Bound n t) sc)
1429getFixedInType i env (_ : is) (Bind n (Pi t) sc)
1441getFixedInType i env (_ : is) (Bind n (Pi t) sc)
1430 = getFixedInType i (n : env) is (instantiate (P Bound n t) sc)
1442 = getFixedInType i (n : env) is (instantiate (P Bound n t) sc)
1431getFixedInType i env is tm@(App f a)
1443getFixedInType i env is tm@(App f a)