Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Function0 syntax #3185

Merged
merged 1 commit into from
Dec 3, 2019
Merged

Conversation

travisbrown
Copy link
Contributor

Another Dotty-friendliness change. To be honest I don't think I even realized that eta-expansion syntax could be used for Function0 in Scala 2. It doesn't work on Dotty:

4 |  def mk1(x: => String): Thunk = new Thunk(x _)
  |                                           ^^^
  |Only function types can be followed by _ but the current expression has type String

I think it makes sense to change these now. For me at least the () => x syntax is less bizarre and surprising anyway.

I double-checked that they compile to the same thing.

class Thunk(val value: () => String)

object Thunk {
  def mk1(x: => String): Thunk = new Thunk(x _)
  def mk2(x: => String): Thunk = new Thunk(() => x)
}

Becomes:

  public static Thunk mk2(scala.Function0<java.lang.String>);
    descriptor: (Lscala/Function0;)LThunk;
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=1, args_size=1
         0: getstatic     #21                 // Field Thunk$.MODULE$:LThunk$;
         3: aload_0
         4: invokevirtual #23                 // Method Thunk$.mk2:(Lscala/Function0;)LThunk;
         7: areturn
    Signature: #14                          // (Lscala/Function0<Ljava/lang/String;>;)LThunk;
    MethodParameters:
      Name                           Flags
      x                              final

  public static Thunk mk1(scala.Function0<java.lang.String>);
    descriptor: (Lscala/Function0;)LThunk;
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=1, args_size=1
         0: getstatic     #21                 // Field Thunk$.MODULE$:LThunk$;
         3: aload_0
         4: invokevirtual #26                 // Method Thunk$.mk1:(Lscala/Function0;)LThunk;
         7: areturn
    Signature: #14                          // (Lscala/Function0<Ljava/lang/String;>;)LThunk;
    MethodParameters:
      Name                           Flags
      x                              final

@codecov-io
Copy link

codecov-io commented Dec 3, 2019

Codecov Report

Merging #3185 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3185   +/-   ##
=======================================
  Coverage   92.99%   92.99%           
=======================================
  Files         376      376           
  Lines        7381     7381           
  Branches      195      195           
=======================================
  Hits         6864     6864           
  Misses        517      517
Flag Coverage Δ
#scala_version_212 93.31% <100%> (-0.02%) ⬇️
#scala_version_213 90.59% <100%> (ø) ⬆️
Impacted Files Coverage Δ
core/src/main/scala/cats/Eval.scala 98.83% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8253462...fa89d11. Read the comment docs.

@LukaJCB LukaJCB merged commit 7035298 into typelevel:master Dec 3, 2019
@travisbrown travisbrown added this to the 2.1.0-RC3 milestone Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants