Scala runtime continuation restriction error

Scala is new here, I just downloaded Eclipse 3.6.2 and Scala IDE 2.0.0-beta4 (with Scala 2.9.0.final). I am creating a new Scala project to try differentiated sequels:

package delimCCTests import scala.util.continuations._ object Test extends App { val result = reset { 1 + shift { k: (Int => Int) => k(k(5)) } + 1 } println(result) } 

This compiles fine, then I click Run as -> Scala application and get this exception:

 Exception in thread "main" java.lang.NoSuchMethodError: scala.util.continuations.package$.shift(Lscala/Function1;)Ljava/lang/Object; at delimCCTests.Test$$anonfun$1.apply$mcI$sp(DelimCCTests.scala:7) at delimCCTests.Test$$anonfun$1.apply(DelimCCTests.scala:7) at delimCCTests.Test$$anonfun$1.apply(DelimCCTests.scala:7) at scala.util.continuations.package$.reset(package.scala:20) at delimCCTests.Test$delayedInit$body.apply(DelimCCTests.scala:6) at scala.Function0$class.apply$mcV$sp(Function0.scala:34) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App$$anonfun$main$1.apply(App.scala:60) at scala.App$$anonfun$main$1.apply(App.scala:60) at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) at scala.collection.immutable.List.foreach(List.scala:45) at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30) at scala.App$class.main(App.scala:60) at delimCCTests.Test$.main(DelimCCTests.scala:5) at delimCCTests.Test.main(DelimCCTests.scala) 

What am I doing wrong? Am I missing any configuration?

BTW I thought the compiler deduced the continuation type? This article uses:

 val result = reset { 1 + shift { k => k(k(5)) } + 1 } 

but this does not compile in my environment ...

+6
source share
2 answers

This error means that you did not add the Scala CPS plugin - it is not part of the standard assembly (yet). Put the jar in the classpath and run Scala to continue:

 $ scala -P:continuations:enable 
+3
source

This can be resolved in eclipse by adding the CPS plugin class to the Scala section of Compiler> Advanced, and also turning on the switch:

Enabling the continuations switchAdding the plugin and setting the plugins path Xplugin should be scala.tools.selectivecps.SelectiveCPSPlugin , and Xpluginsdir should be a dir that contains org.scala-lang.plugins.scala-continuations-plugin.jar

+1
source

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


All Articles