@@ -176,25 +176,35 @@ && whnf(type) instanceof DataCall dataCall
176176 var A = arg .get (1 );
177177 // check each clause
178178 MutableList <PartialTerm .Clause > cls = MutableList .create ();
179- MutableList <ConjCofNF > allCof = MutableList .create ();
179+ MutableList <Term > allCof = MutableList .create ();
180180 for (var rcls : clause ) {
181- var clsCof = elabCof (rcls .cof ());
182- var clsRhs = inherit (rcls .tm (), A ).wellTyped ();
183- cls .append (new PartialTerm .Clause (clsCof , clsRhs ));
184- allCof .append (clsCof );
181+ var clsCof = inherit (rcls .cof (), state ().primFactory .getCall (PrimDef .ID .COF ));
182+ var clsCofNF = expand (clsCof .wellTyped ());
183+ if (clsCofNF == null ) {
184+ yield fail (expr .data (), type , new IllegalPartialElement .BadPartialLHS (clsCof .wellTyped (), rcls .cof ().sourcePos (), state ()));
185+ }
186+ var clsRhs = withConnection (clsCofNF , () -> inherit (rcls .tm (), A ).wellTyped (), () -> inherit (rcls .tm (), A ).wellTyped ());
187+ cls .append (new PartialTerm .Clause (clsCofNF , clsRhs ));
188+ allCof .append (clsCof .wellTyped ());
185189 }
186190 // coverage. cof <=> allCof
187191 var disj = expand (cof );
188- var cnf = new DisjCofNF (allCof .toSeq ());
192+ var cnf = new DisjCofNF (ImmutableSeq .empty ());
193+ if (!allCof .isEmpty ()) {
194+ cnf = expand (allCof .drop (1 ).foldRight (allCof .get (0 ), (l , r ) ->
195+ state ().primFactory .getCall (PrimDef .ID .COF_OR , ImmutableSeq .of (l ,r )) ));
196+ }
197+ if (disj == null || cnf == null ) {
198+ yield fail (expr .data (), type , BadTypeError .partialElement (state , expr , type ));
199+ }
189200 if (!(unifier (expr .sourcePos (), Ordering .Eq ).cofibrationEquiv (disj , cnf )))
190201 yield fail (expr .data (), type , new IllegalPartialElement .CofMismatch (disj , cnf , expr .sourcePos (), state ()));
191202 // boundary
192203 for (@ Closed var c1 : cls )
193204 for (@ Closed var c2 : cls ) {
194205 if (c1 == c2 ) continue ;
195- if (!(withConnection (c1 .cof ().add (c2 .cof ().descent (whnfVisitor ())),
196- () -> unifier (expr .sourcePos (), Ordering .Eq ).compare (c1 .tm (), c2 .tm (), A ) == Decision .YES ,
197- () -> true )))
206+ if (!(withConnection (expandAnd (c1 .cof (), (c2 .cof ().descent (whnfVisitor ()))),
207+ () -> unifier (expr .sourcePos (), Ordering .Eq ).compare (c1 .tm (), c2 .tm (), A ) == Decision .YES )))
198208 yield fail (expr .data (), type , new IllegalPartialElement .ValueMismatch (c1 , c2 , expr .sourcePos (), state ()));
199209 }
200210 yield new Jdg .Default (new PartialTerm (cls .toSeq ()), type );
0 commit comments