Skip to content

Commit b7fd016

Browse files
committed
test: fix
1 parent c029899 commit b7fd016

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

Diff for: base/src/main/java/org/aya/resolve/salt/AyaBinOpSet.java

+7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import kala.collection.immutable.ImmutableSeq;
66
import org.aya.resolve.context.Context;
77
import org.aya.resolve.error.OperatorError;
8+
import org.aya.syntax.core.def.TyckAnyDef;
89
import org.aya.tyck.tycker.Problematic;
910
import org.aya.util.binop.BinOpSet;
11+
import org.aya.util.binop.OpDecl;
1012
import org.aya.util.error.SourcePos;
1113
import org.aya.util.reporter.Reporter;
1214
import org.jetbrains.annotations.NotNull;
@@ -15,6 +17,11 @@ public final class AyaBinOpSet extends BinOpSet implements Problematic {
1517
public final @NotNull Reporter reporter;
1618
public AyaBinOpSet(@NotNull Reporter reporter) { this.reporter = reporter; }
1719
@Override public @NotNull Reporter reporter() { return reporter; }
20+
@Override public boolean equals(@NotNull OpDecl lhs, @NotNull OpDecl rhs) {
21+
if (lhs instanceof TyckAnyDef<?> wrapper) lhs = wrapper.ref.concrete;
22+
if (rhs instanceof TyckAnyDef<?> wrapper) rhs = wrapper.ref.concrete;
23+
return lhs == rhs;
24+
}
1825
@Override protected void reportSelfBind(@NotNull SourcePos sourcePos) {
1926
fail(new OperatorError.SelfBind(sourcePos));
2027
throw new Context.ResolvingInterruptedException();

Diff for: base/src/main/java/org/aya/resolve/salt/ExprBinParser.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,27 @@ public ExprBinParser(@NotNull ResolveInfo resolveInfo, @NotNull SeqView<Expr.@No
3333
new WithPos<>(SourcePos.NONE, new Expr.Error(Doc.english("fakeApp escaped from BinOpParser")))
3434
);
3535

36-
@Override protected @NotNull Expr.NamedArg appOp() {
37-
return OP_APP;
38-
}
36+
@Override protected @NotNull Expr.NamedArg appOp() { return OP_APP; }
3937

4038
@Override protected @NotNull BinOpParser<AyaBinOpSet, WithPos<Expr>, Expr.NamedArg>
4139
replicate(@NotNull SeqView<Expr.@NotNull NamedArg> seq) {
4240
return new ExprBinParser(resolveInfo, seq);
4341
}
4442

4543
@Override protected void reportAmbiguousPred(String op1, String op2, SourcePos pos) {
46-
opSet.reporter.report(new OperatorError.Precedence(op1, op2, pos));
44+
opSet.fail(new OperatorError.Precedence(op1, op2, pos));
4745
}
4846

4947
@Override protected @NotNull WithPos<Expr> createErrorExpr(@NotNull SourcePos sourcePos) {
5048
return new WithPos<>(sourcePos, new Expr.Error(Doc.english("an application")));
5149
}
5250

5351
@Override protected void reportFixityError(Assoc top, Assoc current, String topOp, String currentOp, SourcePos pos) {
54-
opSet.reporter.report(new OperatorError.Fixity(currentOp, current, topOp, top, pos));
52+
opSet.fail(new OperatorError.Fixity(currentOp, current, topOp, top, pos));
5553
}
5654

5755
@Override protected void reportMissingOperand(String op, SourcePos pos) {
58-
opSet.reporter.report(new OperatorError.MissingOperand(pos, op));
56+
opSet.fail(new OperatorError.MissingOperand(pos, op));
5957
}
6058

6159
@Override protected @Nullable OpDecl underlyingOpDecl(@NotNull Expr.NamedArg elem) {

Diff for: cli-impl/src/main/java/org/aya/cli/interactive/ReplCompiler.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import kala.control.Either;
77
import kala.function.CheckedFunction;
88
import kala.value.MutableValue;
9+
import org.aya.cli.library.LibraryCompiler;
10+
import org.aya.cli.library.incremental.CompilerAdvisor;
11+
import org.aya.cli.library.json.LibraryConfigData;
912
import org.aya.cli.library.source.LibraryOwner;
1013
import org.aya.cli.single.CompilerFlags;
1114
import org.aya.cli.single.SingleAyaFile;
@@ -100,15 +103,14 @@ public void loadToContext(@NotNull Path file) throws IOException {
100103

101104
private void loadLibrary(@NotNull Path libraryRoot) throws IOException {
102105
var flags = new CompilerFlags(CompilerFlags.Message.EMOJI, false, true, null, modulePaths.view(), null);
103-
throw new UnsupportedOperationException("TODO");
104-
// try {
105-
// var compiler = LibraryCompiler.newCompiler(primFactory, reporter, flags, CompilerAdvisor.onDisk(), libraryRoot);
106-
// compiler.start();
107-
// var owner = compiler.libraryOwner();
108-
// importModule(owner);
109-
// } catch (LibraryConfigData.BadConfig bad) {
110-
// reporter.reportString("Cannot load malformed library: " + bad.getMessage(), Problem.Severity.ERROR);
111-
// }
106+
try {
107+
var compiler = LibraryCompiler.newCompiler(primFactory, reporter, flags, CompilerAdvisor.onDisk(), libraryRoot);
108+
compiler.start();
109+
var owner = compiler.libraryOwner();
110+
importModule(owner);
111+
} catch (LibraryConfigData.BadConfig bad) {
112+
reporter.reportString("Cannot load malformed library: " + bad.getMessage(), Problem.Severity.ERROR);
113+
}
112114
}
113115

114116
private void importModule(@NotNull LibraryOwner owner) {
@@ -119,7 +121,7 @@ private void importModule(@NotNull LibraryOwner owner) {
119121
owner.libraryDeps().forEach(this::importModule);
120122
}
121123

122-
/** @see org.aya.cli.single.SingleFileCompiler#compile(Path, Function, CompilerFlags, ModuleCallback) */
124+
/** @see org.aya.cli.single.SingleFileCompiler#compile(Path, ModuleCallback) */
123125
private void loadFile(@NotNull Path file) {
124126
compileToContext(parser -> Either.left(fileManager.createAyaFile(locator, file).parseMe(parser)), NormalizeMode.HEAD);
125127
}

Diff for: tools-kala/src/main/java/org/aya/util/binop/BinOpSet.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public Assoc assocOf(@Nullable OpDecl opDecl) {
3939
return ensureHasElem(opDecl).assoc;
4040
}
4141

42+
public abstract boolean equals(@NotNull OpDecl lhs, @NotNull OpDecl rhs);
43+
4244
public final boolean isOperand(@Nullable OpDecl opDecl) {
4345
return opDecl == null || opDecl.opInfo() == null;
4446
}
@@ -48,7 +50,7 @@ public BinOP ensureHasElem(@NotNull OpDecl opDecl) {
4850
}
4951

5052
public BinOP ensureHasElem(@NotNull OpDecl opDecl, @NotNull SourcePos sourcePos) {
51-
var elem = ops.find(e -> e.op == opDecl);
53+
var elem = ops.find(e -> equals(e.op, opDecl));
5254
if (elem.isDefined()) return elem.get();
5355
var newElem = BinOP.from(sourcePos, opDecl);
5456
ops.add(newElem);

0 commit comments

Comments
 (0)