Skip to content

Commit

Permalink
fix: Avoid generating names in constructor field which clash with params
Browse files Browse the repository at this point in the history
Signed-off-by: George Thomas <[email protected]>
  • Loading branch information
georgefst committed May 30, 2023
1 parent f735c75 commit f353179
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions primer/src/Primer/Action/Available.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import Primer.Primitives (tChar, tInt)
import Primer.Questions (
generateNameExpr,
generateNameTy,
generateNameTyAvoiding,
variablesInScopeExpr,
variablesInScopeTy,
)
Expand Down Expand Up @@ -490,8 +491,8 @@ options typeDefs defs cxt level def0 sel0 = \case
Left zE -> generateNameExpr typeOrKind zE
Right zT -> generateNameTy typeOrKind zT
SelectionTypeDef sel -> do
(_, zT) <- conField sel
pure $ generateNameTy typeOrKind zT
(def, zT) <- conField sel
pure $ generateNameTyAvoiding (unLocalName . fst <$> astTypeDefParameters def) typeOrKind zT
varsInScope = case sel0 of
SelectionDef sel -> do
nodeSel <- sel.node
Expand Down
12 changes: 11 additions & 1 deletion primer/src/Primer/Questions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Primer.Questions (
ShadowedVarsTy (..), -- only exported for testing
generateNameExpr,
generateNameTy,
generateNameTyAvoiding,
uniquify,
) where

Expand Down Expand Up @@ -100,9 +101,18 @@ generateNameTy ::
Either (Maybe (Type' ())) (Maybe Kind) ->
TypeZip ->
m [Name]
generateNameTy = generateNameTyAvoiding []

generateNameTyAvoiding ::
MonadReader Cxt m =>
[Name] ->
Either (Maybe (Type' ())) (Maybe Kind) ->
TypeZip ->
m [Name]
-- It doesn't really make sense to ask for a term variable (Left) here, but
-- it doesn't harm to support it
generateNameTy tk z = uniquifyMany <$> mkAvoidForFreshNameTy z <*> baseNames tk
generateNameTyAvoiding avoiding tk z =
uniquifyMany <$> ((Set.fromList avoiding <>) <$> mkAvoidForFreshNameTy z) <*> baseNames tk

baseNames ::
MonadReader Cxt m =>
Expand Down

0 comments on commit f353179

Please sign in to comment.