google / guice

Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 11 and above, brought to you by Google.
https://github.com/google/guice
Apache License 2.0
12.42k stars 1.66k forks source link

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

Closed gissuebot closed 10 years ago

gissuebot commented 10 years ago

From peter.hausel on January 15, 2009 07:37:29

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: http://code.google.com/p/google-guice/issues/detail?id=310

gissuebot commented 10 years ago

From limpbizkit on April 26, 2009 14:41:50

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...

Status: WontFix
Labels: Extension-Servlet Priority-Low Type-Defect

gissuebot commented 10 years ago

From fede.silva on April 26, 2009 16:09:22

something like this fixes it in the scala side: http://gist.github.com/94688

gissuebot commented 10 years ago

From james.strachan on March 30, 2010 03:26:59

@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.java: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)

gissuebot commented 10 years ago

From james.strachan on March 30, 2010 03:43:33

@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

gissuebot commented 10 years ago

From james.strachan on March 30, 2010 03:44:13

In summary, this workaround seems to work fine for me in scala...

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