Skip to content

Commit

Permalink
pat: do insert pats before classifier
Browse files Browse the repository at this point in the history
Co-authored-by: Hoshino Tented <[email protected]>
  • Loading branch information
ice1000 and HoshinoTented committed Jan 4, 2025
1 parent c4fba2c commit c2bf007
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion base/src/main/java/org/aya/tyck/ExprTycker.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ && whnf(type) instanceof DataCall dataCall
new ClauseTycker(this),
telescope,
new DepTypeTerm.Unpi(ImmutableSeq.empty(), type),
ImmutableSeq.fill(discriminant.size(), i -> new LocalVar("match" + i)),
ImmutableSeq.fill(discriminant.size(), i ->
new LocalVar("match" + i, discriminant.get(i).sourcePos(), GenerateKind.Basic.Tyck)),
ImmutableSeq.empty(),
clauses, true);
var wellClauses = clauseTycker.check(exprPos)
Expand Down
12 changes: 10 additions & 2 deletions base/src/main/java/org/aya/tyck/pat/ClauseTycker.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.aya.syntax.core.pat.PatToTerm;
import org.aya.syntax.core.pat.TypeEraser;
import org.aya.syntax.core.term.*;
import org.aya.syntax.ref.GenerateKind;
import org.aya.syntax.ref.LocalCtx;
import org.aya.syntax.ref.LocalVar;
import org.aya.tyck.ExprTycker;
Expand Down Expand Up @@ -187,11 +188,18 @@ public record Worker(
ctx = ctx.map(new TermInline());
var patWithTypeBound = Pat.collectVariables(patResult.wellTyped().view());

var unpiBody = sigIter.unpiBody();
// fill missing patterns
var missingPats = unpiBody.params().mapIndexed((idx, x) ->
// It would be nice if we have a SourcePos here
new Pat.Bind(new LocalVar("unpi" + idx, SourcePos.NONE, GenerateKind.Basic.Tyck), x.type()));

var allBinds = patWithTypeBound.component1().toImmutableSeq();
var newClause = new Pat.Preclause<>(clause.sourcePos, patWithTypeBound.component2(),
allBinds.size(), patIter.exprBody());
return new LhsResult(ctx, sigIter.unpiBody(), allBinds,
patResult.wellTyped(), patResult.paramSubst(), patResult.asSubst(), newClause, patResult.hasError());
patResult.wellTyped().appendedAll(missingPats),
patResult.paramSubst(), patResult.asSubst(), newClause, patResult.hasError());
}
}

Expand Down Expand Up @@ -225,7 +233,7 @@ else if (result.hasError) {
exprTycker.solveMetas();
wellBody = zonker.zonk(wellBody);

// fill missing patterns and eta body
// eta body with inserted patterns
wellBody = AppTerm.make(wellBody, result.unpiPats().map(PatToTerm::visit));

// bind all pat bindings
Expand Down

0 comments on commit c2bf007

Please sign in to comment.