Skip to content

Commit

Permalink
fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellwrosen committed Sep 19, 2024
1 parent 4d70772 commit 7827f9f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions unison-core/src/Unison/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -598,23 +598,34 @@ suffixifyByHashName fqn rel =

isOk :: Name -> Bool
isOk suffix =
numLocalNames == 0 && (Set.size matchingRefs == 1 || matchingRefs == allRefs)
(Set.size matchingRefs == 1 || matchingRefs == allRefs)
-- Don't use a suffix of 2+ aliases if any of then are non-local names
&& case numLocalNames of
0 -> True
1 -> numNonLocalNames == 0
_ -> False
where
numLocalNames :: Int
numNonLocalNames :: Int
matchingRefs :: Set r
(getSum -> numLocalNames, unNamePriority -> matchingRefs) =
(getSum -> numLocalNames, getSum -> numNonLocalNames, unNamePriority -> matchingRefs) =
R.searchDomG f (compareSuffix suffix) rel
where
f :: Name -> Set r -> (Sum Int, NamePriority (Set r))
f :: Name -> Set r -> (Sum Int, Sum Int, NamePriority (Set r))
f name refs =
(numLocal, refs <$ nameLocationPriority location)
(numLocal, numNonLocal, refs <$ nameLocationPriority location)
where
location = classifyNameLocation name
numLocal =
case location of
NameLocation'Local -> Sum 1
NameLocation'DirectDep -> Sum 0
NameLocation'IndirectDep -> Sum 0
numNonLocal =
case location of
NameLocation'Local -> Sum 0
NameLocation'DirectDep -> Sum 1
NameLocation'IndirectDep -> Sum 1

-- | Returns the common prefix of two names as segments
--
Expand Down

0 comments on commit 7827f9f

Please sign in to comment.