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

Fix #1693 #1708

Merged
Merged
Show file tree
Hide file tree
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
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
5 changes: 0 additions & 5 deletions test/Internal/Eval/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ tests =
$(mkRelDir ".")
$(mkRelFile "IdenFunctionArgsImplicit.juvix")
$(mkRelFile "out/IdenFunctionArgsImplicit.out"),
PosTest
"A function with no explicit arguments"
$(mkRelDir ".")
$(mkRelFile "IdenFunctionArgsNoExplicit.juvix")
$(mkRelFile "out/IdenFunctionArgsNoExplicit.out"),
PosTest
"A module that imports another"
$(mkRelDir "Import")
Expand Down
7 changes: 7 additions & 0 deletions test/Typecheck/Negative.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ tests =
$(mkRelFile "WrongReturnTypeTooManyArguments.juvix")
$ \case
ErrExpectedFunctionType {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous hole"
$(mkRelDir "Internal")
$(mkRelFile "IdenFunctionArgsNoExplicit.juvix")
$ \case
ErrUnsolvedMeta {} -> Nothing
_ -> wrongError
]

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")
]
1 change: 0 additions & 1 deletion tests/Internal/positive/out/IdenFunctionArgsNoExplicit.out

This file was deleted.

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 := 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.