Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exact match on term types when determining whether doc or test. #4408

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions unison-share-api/src/Unison/Server/Backend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,11 @@ isDoc codebase ref = do

isDoc' :: (Var v, Monoid loc) => Maybe (Type v loc) -> Bool
isDoc' typeOfTerm = do
-- A term is a dococ if its type conforms to the `Doc` type.
-- A term is a doc if its type conforms to the `Doc` type.
case typeOfTerm of
Just t ->
Typechecker.isSubtype t doc1Type
|| Typechecker.isSubtype t doc2Type
Typechecker.isEqual t doc1Type
|| Typechecker.isEqual t doc2Type
Nothing -> False

doc1Type :: (Ord v, Monoid a) => Type v a
Expand All @@ -507,7 +507,7 @@ doc2Type = Type.ref mempty DD.doc2Ref
isTestResultList :: forall v a. (Var v, Monoid a) => Maybe (Type v a) -> Bool
isTestResultList typ = case typ of
Nothing -> False
Just t -> Typechecker.isSubtype t resultListType
Just t -> Typechecker.isEqual t resultListType

resultListType :: (Ord v, Monoid a) => Type v a
resultListType = Type.app mempty (Type.list mempty) (Type.ref mempty Decls.testResultRef)
Expand Down Expand Up @@ -553,15 +553,11 @@ getTermTag ::
m TermTag
getTermTag codebase r sig = do
-- A term is a doc if its type conforms to the `Doc` type.
let isDoc = case sig of
Just t ->
Typechecker.isSubtype t (Type.ref mempty Decls.docRef)
|| Typechecker.isSubtype t (Type.ref mempty DD.doc2Ref)
Nothing -> False
let isDoc = isDoc' sig
-- A term is a test if it has the type [test.Result]
let isTest = case sig of
Just t ->
Typechecker.isSubtype t (Decls.testResultType mempty)
Typechecker.isEqual t (Decls.testResultType mempty)
Nothing -> False
constructorType <- case r of
V2Referent.Ref {} -> pure Nothing
Expand Down Expand Up @@ -1012,7 +1008,7 @@ docsForDefinitionName codebase (NameSearch {termSearch}) name = do
Referent.Ref r ->
maybe [] (pure . (r,)) <$> Codebase.getTypeOfTerm codebase r
_ -> pure []
pure [r | (r, t) <- rts, Typechecker.isSubtype t (Type.ref mempty DD.doc2Ref)]
pure [r | (r, t) <- rts, isDoc' (Just t)]

-- | Evaluate and render the given docs
renderDocRefs ::
Expand Down
Loading