scalacenter / scala-syntax

Scalameta pretty printer for better Scalafix refactorings
Apache License 2.0
17 stars 6 forks source link

Fix infix operator of different precedence #26

Closed MasseGuillaume closed 6 years ago

MasseGuillaume commented 6 years ago

for example:

a :: (b o_: c)

ApplyInfix(
  a,
  ::,            // precedence = 7
  ApplyInfix(
    b,
    o_:,         // precedence = 1
    c
  )
)

previously:

val isLeft = outerOperatorIsLeftAssociative    // false
val isRight = !outerOperatorIsLeftAssociative  // true (outer ends with `:` therefore rightAssociative)

if (outerOperatorPrecedence < innerOperatorPrecedence) {
  isRight
}
else if (outerOperatorPrecedence > innerOperatorPrecedence) { // true
  isLeft // false
}
else {
  isLeft ^ side.isLeft
}

it would not be a problem for a :: b :: c since it would fall in the else case

isLeft ^ side.isLeft // false ^ true = true

codecov[bot] commented 6 years ago

Codecov Report

Merging #26 into master will increase coverage by 0.1%. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master     #26     +/-   ##
========================================
+ Coverage    86.4%   86.5%   +0.1%     
========================================
  Files          15      15             
  Lines         802     808      +6     
  Branches       32      39      +7     
========================================
+ Hits          693     699      +6     
  Misses        109     109
Impacted Files Coverage Δ
...rc/main/scala/org/scalafmt/internal/TokenOps.scala 85.71% <100%> (+1.99%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ceb75f3...7f21455. Read the comment docs.