Scala warning without line number - scala

I am seeing a few of these warnings in my build:
At the end of the day, could not inline #inline-marked method ->$extension
These are produced by using operator -> in Map in scala 2.10 (I can't move to scala 2.12 right now).
but no line number is provided. Is there a scala compiler option I need to turn on to get line number details?

Related

Intellij Scala worksheet Run type difference explain

In Intellij Scala Worksheet support, what is the difference between the Run types i.e PLAIN vs REPL ?
Plain evaluation model compiles the whole worksheet in one go before evaluating expressions, whilst REPL evaluation model evaluates each expression on the go before moving to the next one.
Adding an expression in REPL mode evaluates incrementally just that new expression, whilst in Plain mode it would re-interpret the whole worksheet from the beginning.
An example where the difference matters is when defining companion objects. Similarly to how in Scala REPL proper we have to use :paste command to define companion, in IntelliJ Scala Worksheet we have to use Plain run type.
REPL mode as it says READ EVALUATE PRINT LOOP is kind of interpreter i.e. each expression will be evaluated after to move to next line.. It is generally used to make quick logic checks.
while in worksheet mode you need to make an object or class.. worksheet is the traditional OOPS way like we do in java and whole file is compiled in one go.

Upgrade to Sbt 0.13.8 but got several warnings "detected an interpolated expression" for strings with dollar sign

I upgraded my app to Play 2.4 and sbt 0.13.8. Our code has few string variables that contain string value like "${fn}". However, after upgrading to sbt 0.13.8, it started showing this warning:
possible missing interpolator: detected an interpolated expression
[warn] var email = format.replace("${fn}", fn)
[warn] ^
I have tried using triple quoted strings but the warnings still won't go away.
If you want to keep -Xlint (which is generally a good idea), you can avoid the warning by writing s"$${fn}".
It seems to be a false positive generated by the compiler linter. You can try to either remove the linter compiler flag (look for -Xlint in your compiler flags) or you can upgrade to Scala 2.11.7 and sbt 0.13.9 to see if the false positive fix is picked up.
Scala has a standard mechanism for replacing expressions between ${...} in strings. To make this work, you have to prepend the string with s. For example:
val fn = "someone#somewhere.com"
var email = s"${fn}" // email will be: "someone#somewhere.com"
Scala, or sbt, sees that you've used ${...} in a string literal, but that there is no s in front of the literal. It's warning you that you might have forgotten to prepend the s.

IntelliJ Scala not recognizing Scala symbols ('foo)

In IntelliJ Scala's debugger, you can open a window to evaluate expressions (alt + F8)
However, it always fails as long as I have Scala symbols in the expression (i.e., 'foobar), saying:
result = Literal has null value
It was a bug. It is fixed now, so all should work in the next version of the scala plugin.
You can use bugtracker for this kind of questions: http://youtrack.jetbrains.com/issue/SCL-6999

Debuggin single lines in Scala

A single of code can achieve a lot in Scala.
def -(that: Nat) = if (that.isZero) this else throw new Error("negative number")
However, it is difficult to debug.
Any tips?
Use scala worksheet. That's it: you'll get multiline REPL with your environment in which you can play with your code.
Alternatively, just use REPL bundled with sbt (sbt console) with proper imports
you can see output of compiler phases, i.e. the AST after desugarings with
scalac -Xprint:typer
scalac -Xprint-types (note hyphen, not colon)
The man page is a little confusing, there's no "typer" phase listed, but it works:
http://www.scala-lang.org/docu/files/tools/scalac.html
Compile time type tracing

Scala REPL fails to autocomplete methods that comes from implicit conversion

if I write in scala 2.10 REPL (interactive Scala shell):
"""\w""".
And press TAB it gives me:
+ asInstanceOf charAt
codePointAt codePointBefore
codePointCount compareTo compareToIgnoreCase
concat contains ....
However, .r is missing. When I put the same string into eclipse, it offers me .r as well. The same is true if I insert import scala.util.matching._ before.
Why REPL is not offering all possibilities?
Even bigger problem REPL has if i try to work with unicode, e.g. I write:
"""\p{L}""".
and press TAB
it gives me error:
scala> """\p{L}""".<console>:1: error: unclosed multi-line string literal
"""
^
Again, it works fine in Eclipse.
Is REPL so buggy, or am I missing something?
Yes, r is missing, but if you write """\w""".r and press enter it nevertheless works res0: scala.util.matching.Regex = \w. Having tab autocompletion for r seems not really neccessary.
The unicode issue is probably caused by java. You can explicitly request UTF-8 if you pass -Dfile.encoding=UTF-8 to java. Here is a post which describes how to do it.
If you use Eclipse, I can reccommend the Scala worksheet plugin which is a very good repl replacement.
The REPL only displays fields and methods of the object, while .r is only available through an implicit conversion (augmentString in scala.Predef) which turns it into a StringOps. There is probably no reason for this besides the fact that it would need to be implemented and nobody got around to doing it. You can still call .r on this, of course.
The Scala IDE is smart enough to resolve implicits, which is why you can see it there.