Skip to content

Commit

Permalink
fix #1693
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Jan 9, 2023
1 parent f126489 commit d996730
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/Juvix/Compiler/Abstract/Data/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ instance Pretty Name where
<> "@"
<> pretty (n ^. nameId)

addNameIdTag :: Bool -> NameId -> Doc a -> Doc a
addNameIdTag showNameId nid
| showNameId = (<> ("@" <> pretty nid))
| otherwise = id

prettyName :: HasNameKindAnn a => Bool -> Name -> Doc a
prettyName showNameId n =
annotate
(annNameKind (n ^. nameKind))
(pretty (n ^. namePretty) <>? uid)
where
uid
| showNameId = Just ("@" <> pretty (n ^. nameId))
| otherwise = Nothing
(addNameIdTag showNameId (n ^. nameId) (pretty (n ^. namePretty)))

type FunctionName = Name

Expand Down
4 changes: 3 additions & 1 deletion src/Juvix/Compiler/Internal/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ instance PrettyCode Function where
return $ funParameter' <+> kwArrow <+> funReturn'

instance PrettyCode Hole where
ppCode _ = return kwHole
ppCode h = do
showNameId <- asks (^. optShowNameIds)
return (addNameIdTag showNameId (h ^. holeId) kwHole)

instance PrettyCode InductiveConstructorDef where
ppCode c = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,8 @@ inferExpression' hint e = case e of
ExpressionLambda l -> goLambda l
where
goHole :: Hole -> Sem r TypedExpression
goHole h =
goHole h = do
void (queryMetavar h)
return
TypedExpression
{ _typedExpression = ExpressionHole h,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-- TODO: RENAME!
module Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.Inference
( module Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.Inference,
module Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.FunctionsTable,
Expand All @@ -7,6 +6,7 @@ where

import Data.HashMap.Strict qualified as HashMap
import Juvix.Compiler.Internal.Extra
import Juvix.Compiler.Internal.Pretty
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.Context
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.FunctionsTable
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Error
Expand Down Expand Up @@ -63,9 +63,14 @@ closeState = \case
Sem r' ()
f m = mapM_ goHole (HashMap.keys m)
where
getState :: Hole -> MetavarState
getState h = fromMaybe err (m ^. at h)
where
err :: a
err = error ("Impossible: could not find the state for the hole " <> ppTrace h)
goHole :: Hole -> Sem r' Expression
goHole h =
let st = fromJust (m ^. at h)
let st = getState h
in case st of
Fresh -> throw (ErrUnsolvedMeta (UnsolvedMeta h))
Refined t -> do
Expand Down
6 changes: 5 additions & 1 deletion test/Typecheck/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,9 @@ tests =
PosTest
"As Patterns"
$(mkRelDir "Internal")
$(mkRelFile "AsPattern.juvix")
$(mkRelFile "AsPattern.juvix"),
PosTest
"Issue 1693 (Inference and higher order functions)"
$(mkRelDir "issue1693")
$(mkRelFile "M.juvix")
]
21 changes: 21 additions & 0 deletions tests/positive/issue1693/M.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module M;
open import Stdlib.Prelude;

S : {A : Type} → {B : Type} → {C : Type} → (A → B → C) → (A → B) → A → C;
S x y z := x z (y z);

K : {A : Type} → {B : Type} → A → B → A;
K x y := x;

I : {A : Type} → A → A;
I {A} := S K (K {_} {Bool});

main : IO;
main := printNatLn
$ I {Nat} 1
+ I I 1
+ I (I 1)
+ I 1
+ I (I I) I (I I I) 1
+ I I I (I I I (I I)) I (I I) I I I 1;
end;
Empty file.

0 comments on commit d996730

Please sign in to comment.