Scala 2.10.0 RC2 and optional parameters

I am experimenting with Scala Macros that are part of Scala 2.10, but when I try to compile (using sbt) I get the following error:

[error] .../API.scala:9: not enough arguments for constructor OAuth: (requestMethod: String, consumerSecret: String, consumerKey: String, signatureMethod: String, version: String)jm.oauth.OAuth [error] private val oauth = new OAuth(OAuth.POST, oauthConsumerSecret, oauthConsumerKey, OAuth.HMAC_SHA1) 

Here you can find an implementation of the OAuth class.

Is there any incompatibility between Scala 2.10 and optional parameters?

The same code compiled with Scala 2.9.1 worked fine.

+4
source share
1 answer

If you create a file containing only this class definition:

 class Optional(x: Int = 0) 

Then compile it with Scala 2.9.2 and run javap in the resulting class, you will see the following:

 public class Optional implements scala.ScalaObject { public static final int init$default$1(); public Optional(int); } 

Compile it again with 2.10.0-RC2 and javap and you will get this instead:

 public class Optional { public static int $lessinit$greater$default$1(); public Optional(int); } 

So, no, the default arguments in version 2.10 are perfectly fine, you just came across a concrete example of the lack of binary compatibility between major versions of Scala.

+7
source

Source: https://habr.com/ru/post/1445408/


All Articles