question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Named arguments reorder effects

See original GitHub issue
def foo(bar: Int, bat: Int) = 1
def p(x: Int) = { println(x); x }

Scala 2.12:

scala> foo(bat = p(1), bar = p(2)) 
1
2

Dotty:

scala> foo(bat = p(1), bar = p(2)) 
2
1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolasstuckicommented, Jul 26, 2017

Here is a nice test case that includes default parameters.

object Test {
  def p(x: Int) = { println(x); x }
  def foo(x1: Int, x2: Int, , x3: Int, x4: Int = p(4), x5: Int = p(5)) = 1
  def main(args: Array[String]) = {
    foo(p(1), p(2), p(3)) // 1 2 3 4 5
    foo(p(1), x2 = p(2), x3 = p(3)) // 1 2 3 4 5
    foo(p(1), x3 = p(3), x2 = p(3)) // 1 3 2 4 5
    foo(p(1), x3 = p(3), x5 = p(5), x2 = p(2)) // 1 3 5 2 4
    foo(p(1), x3 = p(3), x4 = p(4), x2 = p(2)) // 1 3 4 2 5
  }
}
0reactions
nicolasstuckicommented, Jul 28, 2017

I will have a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to automatically reorder named function arguments with ...
Is there any way with Resharper - or any other tool - to automatically reorder named parameters solutionwide so that they can perfectly ......
Read more >
Named and Optional Arguments - C# Programming Guide
Named arguments free you from matching the order of arguments to the order of parameters in the parameter lists of called methods. The...
Read more >
Named parameters - Rosetta Code
Create a function which takes in a number of arguments which are specified by name rather than (necessarily) position, and show how to...
Read more >
PHP 8.0 feature focus: Named Arguments - Platform.sh
In PHP, named parameters are entirely controlled by the caller. All functions and methods are, automatically, named-parameter supporting.
Read more >
Named argument enhancements for function calls #498 - GitHub
By named function arguments, I am referrin. ... arguments specified by name -- You explicitly assign to parameters, order does not typically ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found