Skip to content

Commit

Permalink
fix generation of wildcards in RecordPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Jun 4, 2024
1 parent 371f8f2 commit 6621bf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Juvix/Compiler/Internal/Translation/FromConcrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,11 @@ goRecordPattern r = do

mkPatterns :: Sem r [Internal.PatternArg]
mkPatterns = do
sig <- asks (fromJust . HashMap.lookup (constr ^. Internal.nameId) . (^. S.infoConstructorSigs))
sig <-
asks $
fromJust
. HashMap.lookup (constr ^. Internal.nameId)
. (^. S.infoConstructorSigs)
let maxIdx = length (sig ^. recordNames) - 1
args <- IntMap.toAscList <$> byIndex
execOutputList (go maxIdx 0 args)
Expand All @@ -1267,6 +1271,7 @@ goRecordPattern r = do
| otherwise = do
v <- Internal.freshVar loc ("x" <> show idx)
output (Internal.patternArgFromVar Internal.Explicit v)
go maxIdx (idx + 1) args

goAxiom :: (Members '[Reader DefaultArgsStack, Reader Pragmas, Error ScoperError, Builtins, NameIdGen, Reader S.InfoTable] r) => AxiomDef 'Scoped -> Sem r Internal.AxiomDef
goAxiom a = do
Expand Down
5 changes: 5 additions & 0 deletions tests/positive/RecordPattern.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ type Pair (A B : Type) :=
snd : B
};

type T := t;

partialMatch : Pair T T -> T
| mypair@mkPair@{snd := t} := t;

swap {A B : Type} : Pair A B -> Pair B A
| mkPair@{fst := c1; snd := c2} := mkPair c2 c1;

Expand Down

0 comments on commit 6621bf0

Please sign in to comment.