No by-name parameter type allowed here

I was surprised with this compiler error message.
Is this a real limitation, or is it simply a question of using the correct syntax?

no by-name parameter type allowed here

The error message appears at the function definition site, not the function call-site.
I have a function defined like this.

  def findSimplifier(simplifiers:List[(=> Type)]):Type = {
    simplifiers match {
      case Nil => this
      case s::ss =>
        val t2 = s
        if ( this == t2)
          findSimplifier(ss)
        else
          t2
    }
  }

And the call-site looks like this:

  override def canonicalizeOnce: Type = {
    findSimplifier(List[(=> Type)](
    {
      if (U.contains(EmptyType))
        EmptyType
      else
        this
    },
    {
      IntersectionType.apply(U.distinct)
    }
))
}

It’s a limitation. Not in the sense of technical limitation, but a conscious design decision. Only a parameter can be by-name, not the element of a list.

But what you’re probably looking for is List[() => Type].

I had to change all the call sites from

List({...},
     {...}, 
     {...},
     ...)

to

List(() => {...},
     () => {...}, 
     () => {...},
     ...)

and it works. I was just surprised by the limitation. It is surprising when things don’t compose logically.

By-name parameters are great but are too simplistic. If you need more lazyness in your code you can consider using Eval from cats. (as I just mentioned in other thread)