google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

ServletModuleBuilder uses "with" as part of the EDSL which causing issues with Scala #310

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In Scala 'with' is a keyword so invoking a method called 'with' won't work.
Would it be possible to add a set of extra methods named 'by'? That way
Scala users would be able to use the new servlet extension without any hackery.

Original issue reported on code.google.com by peter.ha...@gmail.com on 15 Jan 2009 at 12:37

GoogleCodeExporter commented 9 years ago
I'm not a fan of constraining our language to permit the keywords in other JVM 
languages. There's a lot of words 
we use: to, in, and bind.

What kinds of hacks are necessary? It seems like this would be a fairly common 
problem in Scala...

Original comment by limpbizkit on 26 Apr 2009 at 9:41

GoogleCodeExporter commented 9 years ago
something like this fixes it in the scala side:
http://gist.github.com/94688

Original comment by fede.silva on 26 Apr 2009 at 11:09

GoogleCodeExporter commented 9 years ago
@limpbizkit - seems with is the only clash with scala I've found with guice. 
'with' in scala is kinda like 
'implements' but for traits. 

@fede that seems to barf on scala 2.8.0 beta 1....

[INFO] java.lang.reflect.InvocationTargetException
[INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO]  at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[INFO]  at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
[INFO]  at java.lang.reflect.Method.invoke(Method.java:597)
[INFO]  at 
org_scala_tools_maven_executions.MainHelper.runMain(MainHelper.java:151)
[INFO]  at 
org_scala_tools_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java
:26)
[ERROR] Caused by: scala.tools.nsc.symtab.Types$TypeError: type mismatch;
[INFO]  found   : <repeated...>[java.lang.String]
[INFO]  required: Seq[java.lang.String]
[ERROR]         at 
scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:318)
[ERROR]         at 
scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:273)
[ERROR]         at 
scala.tools.nsc.typechecker.Infer$Inferencer.typeError(Infer.scala:283)
[ERROR]         at 
scala.tools.nsc.typechecker.Infer$Inferencer.typeErrorTree(Infer.scala:292)
[INFO]  at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1008)
[INFO]  at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3876)

Original comment by james.st...@gmail.com on 30 Mar 2010 at 10:26

GoogleCodeExporter commented 9 years ago
@fede - bizarre - the error I posted only seems to occur if you use `with` (or 
your by() method) inside a loop! 
Very odd - I raised a Scala compiler issue... 
https://lampsvn.epfl.ch/trac/scala/ticket/3230

Original comment by james.st...@gmail.com on 30 Mar 2010 at 10:43

GoogleCodeExporter commented 9 years ago
In summary, this workaround seems to work fine for me in scala...

serve("foo").`with`(classOf[FooServlet])

Original comment by james.st...@gmail.com on 30 Mar 2010 at 10:44