softwaremill / scala-clippy

Good advice for Scala compiler errors
Apache License 2.0
312 stars 20 forks source link

string index out of bounds exception #43

Closed cavapoo2 closed 7 years ago

cavapoo2 commented 7 years ago

Not sure if this is my fault :). this initial code I made is clearly wrong of course, should be just compiler error.im using the 0.5-1-SNAPSHOT on windows 10, using sbt.

` sealed abstract class Tree { def maxPrevious: Float }

case class Node(left: Tree, right: Tree) extends Tree { val maxPrevious = max(left.maxPrevious, right.maxPrevious) }

case class Leaf(from: Int, until: Int, maxPrevious: Float) extends Tree { }

def printTree(tree: Tree, start_index: Int, c:Char):List[(Int,Int,Int,Char)] = { //first iterate a tree print all values tree match { case Leaf(from,to,max) => List((from,to,max,start_index,c)) case Node(left,right) => List(printTree(left,start_index-1,'L'), printTree(right,start_index+1,'R')) } } ` andy.ivy2\cache\org.scala-lang.modules\scala-swing_2.11\bundles\scala-swing_2.11-1.0.1.jar [debug] Forcing garbage collection... java.lang.StringIndexOutOfBoundsException: String index out of range: -2 at java.lang.String.substring(String.java:1967) at com.softwaremill.clippy.StringDiff.markDiff(StringDiff.scala:20) at com.softwaremill.clippy.StringDiff.diff(StringDiff.scala:12) at com.softwaremill.clippy.ClippyPlugin.prettyPrintTypeMismatchError(ClippyPlugin.scala:81) at com.softwaremill.clippy.ClippyPlugin.handleError(ClippyPlugin.scala:34) at com.softwaremill.clippy.ClippyPlugin$$anon$1$$anonfun$$lessinit$greater$1.apply(ClippyPlugin.scala:58) at com.softwaremill.clippy.ClippyPlugin$$anon$1$$anonfun$$lessinit$greater$1.apply(ClippyPlugin.scala:58) at com.softwaremill.clippy.DelegatingReporter.error(DelegatingReporter.scala:56) at scala.tools.nsc.typechecker.Contexts$ImmediateReporter.handleError(Contexts.scala:1365) at scala.tools.nsc.typechecker.Contexts$ContextReporter.issue(Contexts.scala:1242)

adamw commented 7 years ago

but what's the problem, the code compiles and it shouldn't, you're getting some incorrect response from clippy, or...? :)

cavapoo2 commented 7 years ago

hi, code does not compile (which it should not), but should I be getting this exception from compilation ?

adamw commented 7 years ago

Ah, I didn't notice the exception below, sorry :) Of course, you shouldn't, we'll check that :)

kciesielski commented 7 years ago

@arobson73 Thanks for reporting, the issue is now fixed in 0.5.1-SNAPSHOT