From 0945d541b747ea1fd46f29cef714e7659792089a Mon Sep 17 00:00:00 2001 From: Lukasz Czajka Date: Thu, 14 Sep 2023 17:19:28 +0200 Subject: [PATCH 1/2] fix traits bug --- .../FromInternal/Analysis/TypeChecking/Traits/Resolver.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Juvix/Compiler/Internal/Translation/FromInternal/Analysis/TypeChecking/Traits/Resolver.hs b/src/Juvix/Compiler/Internal/Translation/FromInternal/Analysis/TypeChecking/Traits/Resolver.hs index 43e69022c8..9355b019c9 100644 --- a/src/Juvix/Compiler/Internal/Translation/FromInternal/Analysis/TypeChecking/Traits/Resolver.hs +++ b/src/Juvix/Compiler/Internal/Translation/FromInternal/Analysis/TypeChecking/Traits/Resolver.hs @@ -15,8 +15,8 @@ type SubsI = HashMap VarName InstanceParam subsIToE :: SubsI -> SubsE subsIToE = fmap paramToExpression -isTrait :: InfoTable -> InductiveName -> Bool -isTrait tab name = fromJust (HashMap.lookup name (tab ^. infoInductives)) ^. inductiveInfoDef . inductiveTrait +isTrait :: InfoTable -> Name -> Bool +isTrait tab name = maybe False (^. inductiveInfoDef . inductiveTrait) (HashMap.lookup name (tab ^. infoInductives)) resolveTraitInstance :: (Members '[Error TypeCheckerError, NameIdGen, Inference, Reader LocalVars, Reader InfoTable] r) => From 128b589636c2f84bd905694eed2155af2becad49 Mon Sep 17 00:00:00 2001 From: Lukasz Czajka Date: Thu, 14 Sep 2023 18:00:28 +0200 Subject: [PATCH 2/2] add test --- tests/Compilation/positive/out/test061.out | 1 + tests/Compilation/positive/test061.juvix | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tests/Compilation/positive/out/test061.out b/tests/Compilation/positive/out/test061.out index fdabe647f3..01961e4c34 100644 --- a/tests/Compilation/positive/out/test061.out +++ b/tests/Compilation/positive/out/test061.out @@ -10,4 +10,5 @@ just (true) :: nothing :: just (false) :: nil just (1 :: nil) :: nothing :: just (2 :: 3 :: nil) :: nil abba abba! +abba3 a :: b :: c :: d :: nil diff --git a/tests/Compilation/positive/test061.juvix b/tests/Compilation/positive/test061.juvix index 9ef1f0e79f..84e37d3b5c 100644 --- a/tests/Compilation/positive/test061.juvix +++ b/tests/Compilation/positive/test061.juvix @@ -47,6 +47,8 @@ f'3 {A} {{M : Show A}} : A → String := Show.show {{M}}; f'4 {A} {{_ : Show A}} : A → String := Show.show; +f5 {A} {{Show A}} (n : String) (a : A) : String := n ++str Show.show a; + main : IO := printStringLn (Show.show true) >> printStringLn (f false) >> @@ -60,4 +62,5 @@ main : IO := printStringLn (f'4 [just [1]; nothing; just [2; 3]]) >> printStringLn (f'3 "abba") >> printStringLn (f'3 {{M := mkShow (λ{x := x ++str "!"})}} "abba") >> + printStringLn (f5 "abba" 3) >> printStringLn (Show.show ["a"; "b"; "c"; "d"]);