Skip to content

Commit

Permalink
Don't do subtype matching for docs and terms or we'll match fully pol…
Browse files Browse the repository at this point in the history
…ymorphic terms.
  • Loading branch information
ChrisPenner committed Nov 20, 2023
1 parent eb83404 commit af47bee
Showing 1 changed file with 7 additions and 11 deletions.
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

0 comments on commit af47bee

Please sign in to comment.