diff --git a/tools/src/main/java/org/aya/util/error/WithPos.java b/tools/src/main/java/org/aya/util/error/WithPos.java index 6faca5bd..fa6dcac1 100644 --- a/tools/src/main/java/org/aya/util/error/WithPos.java +++ b/tools/src/main/java/org/aya/util/error/WithPos.java @@ -7,8 +7,9 @@ import java.util.function.Function; -public record WithPos(@NotNull SourcePos sourcePos, T data) { +public record WithPos(@NotNull SourcePos sourcePos, T data) implements SourceNode { public @Contract("_->new") WithPos map(@NotNull Function mapper) { - return new WithPos<>(sourcePos, mapper.apply(data)); + var result = mapper.apply(data); + return result == data ? ((WithPos) this) : new WithPos<>(sourcePos, mapper.apply(data)); } }