playframework / playframework/twirl
no type arguments for views?
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 561
- Forks
- 118
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 29
Description
@refried originally filed as https://github.com/playframework/playframework/issues/2194. migrating it here
views/foo1.scala.txt (won't compile)
@[L<:shapeless.Nat:shapeless.ops.nat.ToInt](bar: Bar[L])
@bar has size @shapeless.Nat.toInt[L]
views/foo2.scala.txt (will compile, but silly!)
@(bar: Bar[_<:shapeless.Nat], size: Int)
@bar has size @size
controllers/Application.scala
package controllers
import play.api._
import play.api.mvc._
import shapeless.Nat
import shapeless.ops.nat.ToInt
class Bar[L<:Nat]
object Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
// won't compile
def foo1 = views.txt.foo1(new Bar[Nat._3])
// needlessly complicated
def foo2 = {
def barSize[L<:Nat:ToInt](bar: Bar[L]): Int = Nat.toInt[L]
val bar = new Bar[Nat._3]
val size = barSize(bar)
views.txt.foo2(bar, size)
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The reproducer is in views/foo1.scala.txt and controllers/Application.scala; compare it with the compiling workaround in views/foo2.scala.txt. Start by reproducing the template compilation failure and trace how the type argument and context bounds are handled. Done means foo1 compiles without passing the separately calculated size used by foo2.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100