Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All of a sudden my Scala code expects `;` at the end of each statement

Tags:

scala

sbt

So, basically everything was fine till my last invocation of sbt compile... 2 days back.

But now when I invoke sbt compile, it is expecting every statement to end with ;.

Example:

Following causes problem,

package me.example.sample

import java.util.UUID

Error,

'{' expected but 'import' found.
[error] import java.util.UUID
        ^

But this works fine,

package me.example.sample;

import java.util.UUID;

How do I solve this issue ?

I am running Scala 2.11.5 with Oracle java 1.8.0_40.

like image 728
sarveshseri Avatar asked Mar 30 '15 07:03

sarveshseri


1 Answers

So... In case some one else faces the same problem in future.

Basically Scala avoids semicolons by using line-endings as statement separators.

So... In scala following two things are equivalent:

println( "Hello" ); prinln( "World" )

And

println( "Hello" )
prinln( "World" )

Now, line endings are differently represented in three most popular operating systems.

Windows - CRLF - `\r\n`  
Linux   - LF   - `\n`  
Mac     - CR   - `\r`  

Now, depending on your operating environment, Scala compiler will expect to have corresponding line endings as statement separators otherwise it will be very very confused.

So... In case you get this sort of problem. Please check your line endings.

like image 80
sarveshseri Avatar answered Sep 27 '22 16:09

sarveshseri