Skip to content

Commit

Permalink
Corrected merge logic (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 authored Jun 23, 2023
1 parent bdbcefc commit 51c3ffd
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,15 @@ private [errors] sealed abstract class TrivialDefuncError extends DefuncError {
val cmp = Integer.compareUnsigned(this.underlyingOffset, err.underlyingOffset)
if (cmp > 0) this
else if (cmp < 0) err
else err match {
case err: TrivialDefuncError => new TrivialMergedErrors(this, err)
case err => err
else {
val cmp = Integer.compareUnsigned(this.presentationOffset, err.presentationOffset)
if (cmp > 0) this
else if (cmp < 0) err
else err match {
case err: TrivialDefuncError => new TrivialMergedErrors(this, err)
case err: FancyDefuncError if err.flexibleCaret => new FancyAdjustCaret(err, this)
case err => err
}
}
}

Expand Down Expand Up @@ -227,10 +233,15 @@ private [errors] sealed abstract class FancyDefuncError extends DefuncError {
val cmp = Integer.compareUnsigned(this.underlyingOffset, err.underlyingOffset)
if (cmp > 0) this
else if (cmp < 0) err
else err match {
case err: FancyDefuncError => new FancyMergedErrors(this, err)
case err: TrivialDefuncError if flexibleCaret => new FancyAdjustCaret(this, err)
case _ => this
else {
val cmp = Integer.compareUnsigned(this.presentationOffset, err.presentationOffset)
if (cmp > 0) this
else if (cmp < 0) err
else err match {
case err: FancyDefuncError => new FancyMergedErrors(this, err)
case err: TrivialDefuncError if flexibleCaret => new FancyAdjustCaret(this, err)
case _ => this
}
}
}

Expand Down Expand Up @@ -344,9 +355,10 @@ private [parsley] final class EmptyErrorWithReason(val presentationOffset: Int,

private [errors] final class TrivialMergedErrors private [errors] (val err1: TrivialDefuncError, val err2: TrivialDefuncError) extends TrivialDefuncError {
override final val flags = err1.flags & err2.flags
assume(err1.underlyingOffset == err2.underlyingOffset, "two errors only merge when they have matching offsets")
override val underlyingOffset = err1.underlyingOffset
assume(err1.presentationOffset == err2.presentationOffset, "two errors only merge when they have matching offsets")
override val presentationOffset = err1.presentationOffset //Math.max(err1.offset, err2.offset)
override val underlyingOffset = err1.underlyingOffset
override def makeTrivial(builder: TrivialErrorBuilder): Unit = {
err1.makeTrivial(builder)
err2.makeTrivial(builder)
Expand All @@ -355,9 +367,10 @@ private [errors] final class TrivialMergedErrors private [errors] (val err1: Tri

private [errors] final class FancyMergedErrors private [errors] (val err1: FancyDefuncError, val err2: FancyDefuncError) extends FancyDefuncError {
override final val flags = err1.flags & err2.flags
assume(err1.underlyingOffset == err2.underlyingOffset, "two errors only merge when they have matching offsets")
override val underlyingOffset = err1.underlyingOffset
assume(err1.presentationOffset == err2.presentationOffset, "two errors only merge when they have matching offsets")
override val presentationOffset = err1.presentationOffset //Math.max(err1.offset, err2.offset)
override val underlyingOffset = err1.underlyingOffset
override def makeFancy(builder: FancyErrorBuilder): Unit = {
err1.makeFancy(builder)
err2.makeFancy(builder)
Expand Down

0 comments on commit 51c3ffd

Please sign in to comment.