Skip to content

Commit

Permalink
binop: fix coalesce
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Jun 21, 2024
1 parent bb1f151 commit 4328b18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions base/src/main/java/org/aya/resolve/salt/ExprBinParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public ExprBinParser(@NotNull ResolveInfo resolveInfo, @NotNull SeqView<Expr.@No
@Override public @NotNull Expr.NamedArg makeSectionApp(
@NotNull SourcePos pos, Expr.@NotNull NamedArg op, @NotNull Function<Expr.NamedArg, WithPos<Expr>> lamBody
) {
var missing = Constants.randomlyNamed(op.term().sourcePos());
var defPos = op.term().sourcePos();
var missing = Constants.randomlyNamed(defPos);
var missingElem = new Expr.NamedArg(true, new WithPos<>(
op.term().sourcePos().coaleaseLeft(), new Expr.Ref(missing)));
defPos.coalesceLeft(), new Expr.Ref(missing)));
var missingParam = new Expr.Param(missing.definition(), missing, true);
var term = new Expr.Lambda(missingParam, lamBody.apply(missingElem));
return new Expr.NamedArg(op.explicit(), new WithPos<>(pos, term));
Expand Down
9 changes: 5 additions & 4 deletions tools/src/main/java/org/aya/util/error/SourcePos.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public record SourcePos(
int endColumn
) implements Comparable<SourcePos> {
public SourcePos {
assert tokenEndIndex >= tokenStartIndex;
assert tokenEndIndex >= tokenStartIndex - 1;
}

/** Single instance SourcePos for mocking tests and other usages. */
Expand Down Expand Up @@ -143,8 +143,9 @@ public int hashCode() {

@Override public int compareTo(@NotNull SourcePos o) { return Integer.compare(tokenStartIndex, o.tokenStartIndex); }
public boolean isEmpty() { return length() <= 0; }
private int length() { return tokenEndIndex - tokenStartIndex; }
public @NotNull SourcePos coaleaseLeft() {
return new SourcePos(file, tokenStartIndex, tokenStartIndex, startLine, startColumn, startLine, startColumn);
private int length() { return tokenEndIndex - tokenStartIndex + 1; }
public @NotNull SourcePos coalesceLeft() {
return new SourcePos(file, tokenStartIndex, tokenStartIndex - 1,
startLine, startColumn, startLine, startColumn);
}
}

0 comments on commit 4328b18

Please sign in to comment.