Skip to content

Commit 19dfbfd

Browse files
committed
pat: better impl in case of ind-ind
1 parent 388f2a3 commit 19dfbfd

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

Diff for: base/src/main/java/org/aya/tyck/error/PatternProblem.java

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ record ImplicitDisallowed(@Override @NotNull WithPos<Pattern> pattern) implement
129129
record UnimportedConName(
130130
@Override @NotNull WithPos<Pattern.Bind> pattern
131131
) implements PatternProblem {
132+
@Override
133+
public @NotNull Severity level() {
134+
return Severity.WARN;
135+
}
136+
132137
@Override
133138
public @NotNull Doc describe(@NotNull PrettierOptions options) {
134139
return Doc.vcat(

Diff for: base/src/main/java/org/aya/tyck/pat/PatternTycker.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
import org.aya.generic.term.DTKind;
1414
import org.aya.normalize.Normalizer;
1515
import org.aya.syntax.compile.JitCon;
16+
import org.aya.syntax.compile.JitData;
1617
import org.aya.syntax.concrete.Expr;
1718
import org.aya.syntax.concrete.Pattern;
19+
import org.aya.syntax.concrete.stmt.decl.DataDecl;
1820
import org.aya.syntax.core.Jdg;
19-
import org.aya.syntax.core.def.ConDef;
20-
import org.aya.syntax.core.def.ConDefLike;
21+
import org.aya.syntax.core.def.*;
2122
import org.aya.syntax.core.pat.Pat;
2223
import org.aya.syntax.core.pat.PatMatcher;
2324
import org.aya.syntax.core.pat.PatToTerm;
@@ -156,10 +157,10 @@ public record TyckResult(
156157

157158
// report after tyRef.set, the error message requires it
158159
if (whnf(type) instanceof DataCall call) {
159-
var unimportedCon = call.ref().body()
160-
.filter(con -> con.name().equals(bind.name()));
160+
var unimportedCon = collectConNames(call.ref())
161+
.anyMatch(it -> it.equals(bind.name()));
161162

162-
if (unimportedCon.isNotEmpty()) {
163+
if (unimportedCon) {
163164
fail(new PatternProblem.UnimportedConName(pattern.replace(bindPat)));
164165
}
165166
}
@@ -479,6 +480,17 @@ private record Selection(
479480
};
480481
}
481482

483+
private static @NotNull SeqView<String> collectConNames(@NotNull DataDefLike call) {
484+
return switch (call) {
485+
case JitData jitData -> jitData.body().view().map(AnyDef::name);
486+
case DataDef.Delegate delegate -> {
487+
// the core may be unchecked!
488+
var concrete = (DataDecl) delegate.ref.concrete;
489+
yield concrete.body.view().map(it -> it.ref.name());
490+
}
491+
};
492+
}
493+
482494
/**
483495
* Check whether {@param con} is available under {@param type}
484496
*/

0 commit comments

Comments
 (0)