Why does Scala evaluate the argument for a call-by-name parameter if the method is infix and right-associative?

后端 未结 2 375
别跟我提以往
别跟我提以往 2021-01-17 16:47

As I understood call-by-name parameters of a method, the corresponding argument expression will not be evaluated when passing it to the method, but only when (a

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-17 17:20

    It's a bug. An old one, at that.

    See SI-1980 and PR #2852.

    The linked pull request added a compiler warning when using the -Xlint flag:

    :13: warning: by-name parameters will be evaluated eagerly when called as a right-associative infix operator. For more details, see SI-1980.
             def :: (x: =>Int) = new Node(x)  // a right-associative method
                 ^
    

提交回复
热议问题