-
Notifications
You must be signed in to change notification settings - Fork 21
eta expansion should not precede empty application #7187
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7187?orig=1 |
@retronym said: object Test {
def foo(): () => String = () => ""
val f: () => Any = foo
def main(args: Array[String]): Unit = {
println(f()) // currently, <function0>, would be: ""
}
} I would argue that these are saner semantics, but we need to find a compatible path from here to there. Perhaps we could deprecate and later remove eta expansion when the expected type is Function0. I wonder how much that comes up in the wild. |
@retronym said: |
@retronym said: |
@som-snytt said (edited on Apr 23, 2015 4:48:55 PM UTC): |
@adriaanm said: |
@demobox said (edited on Apr 27, 2015 1:49:12 PM UTC):
doesn't seem quite correct. E.g. here's an example (similar to the one @retronym gave in a previous comment) of code that would no longer compile: class Gate {
def unary_+(): Gate = this
}
val gate = new Gate
def foo(f: () => Gate) = 1
foo(+gate) // currently compiles but would fail if empty application were applied |
@paulp said: |
@demobox said: [~paulp]: I'd agree with that. My comment wasn't clear: I was only trying to point out that the proposed change could cause existing code to break/fail to compile. The change itself seems desirable to me too - I don't see the current behaviour as an advantage. |
@paulp said: Indeed. However that's true of every nontrivial change and most trivial ones. I intended the statement for a fictional universe in which sane semantics are a priority, and in that universe it doesn't come up that empty application can hurt eta-expansion because when it does it's a bug. |
@lrytz said (edited on Aug 11, 2016 9:08:22 AM UTC): |
@adriaanm said: |
Fixes scala/bug#7187 scala#5327 deprecates eta-expansion of zero-arg method values. This removes it in 2.13.
Implemented under -Xsource:2.13 in scala/scala#6475 |
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) - 3.0: auto-application takes precedence, but otherwise we always eta-expand warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined`
Changed my mind -- see scala/scala#7660 |
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) - 3.0: auto-application takes precedence, but otherwise we always eta-expand warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined`
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) - 3.0: auto-application takes precedence, but otherwise we always eta-expand warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined`
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) - 3.0: auto-application takes precedence, but otherwise we always eta-expand warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined`
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined` TODO decide -- currently the condition is more involved to give slack to Scala methods overriding Java-defined ones; I think we should resolve that by introducing slack in overriding e.g. a Java-defined `def toString()` by a Scala-defined `def toString`. This also works better for dealing with accessors overriding Java-defined methods. The current strategy in methodSig is problematic: > // Add a () parameter section if this overrides some method with () parameters > val vparamSymssOrEmptyParamsFromOverride = This means an accessor that overrides a Java-defined method gets a MethodType instead of a `NullaryMethodType`, which breaks lots of assumptions about accessors
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined` TODO decide -- currently the condition is more involved to give slack to Scala methods overriding Java-defined ones; I think we should resolve that by introducing slack in overriding e.g. a Java-defined `def toString()` by a Scala-defined `def toString`. This also works better for dealing with accessors overriding Java-defined methods. The current strategy in methodSig is problematic: > // Add a () parameter section if this overrides some method with () parameters > val vparamSymssOrEmptyParamsFromOverride = This means an accessor that overrides a Java-defined method gets a MethodType instead of a `NullaryMethodType`, which breaks lots of assumptions about accessors
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined` TODO decide -- currently the condition is more involved to give slack to Scala methods overriding Java-defined ones; I think we should resolve that by introducing slack in overriding e.g. a Java-defined `def toString()` by a Scala-defined `def toString`. This also works better for dealing with accessors overriding Java-defined methods. The current strategy in methodSig is problematic: > // Add a () parameter section if this overrides some method with () parameters > val vparamSymssOrEmptyParamsFromOverride = This means an accessor that overrides a Java-defined method gets a MethodType instead of a `NullaryMethodType`, which breaks lots of assumptions about accessors
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined` TODO decide -- currently the condition is more involved to give slack to Scala methods overriding Java-defined ones; I think we should resolve that by introducing slack in overriding e.g. a Java-defined `def toString()` by a Scala-defined `def toString`. This also works better for dealing with accessors overriding Java-defined methods. The current strategy in methodSig is problematic: > // Add a () parameter section if this overrides some method with () parameters > val vparamSymssOrEmptyParamsFromOverride = This means an accessor that overrides a Java-defined method gets a MethodType instead of a `NullaryMethodType`, which breaks lots of assumptions about accessors
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined` TODO decide -- currently the condition is more involved to give slack to Scala methods overriding Java-defined ones; I think we should resolve that by introducing slack in overriding e.g. a Java-defined `def toString()` by a Scala-defined `def toString`. This also works better for dealing with accessors overriding Java-defined methods. The current strategy in methodSig is problematic: > // Add a () parameter section if this overrides some method with () parameters > val vparamSymssOrEmptyParamsFromOverride = This means an accessor that overrides a Java-defined method gets a MethodType instead of a `NullaryMethodType`, which breaks lots of assumptions about accessors
Reverse course from the deprecation introduced in 2.12. (4.3) condition for eta-expansion by -Xsource level: - until 2.13: - for arity > 0: function or sam type is expected - for arity == 0: Function0 is expected -- SAM types do not eta-expand because it could be an accidental SAM scala/bug#9489 - 2.14: - for arity > 0: unconditional - for arity == 0: a function-ish type of arity 0 is expected (including SAM) warnings: - 2.12: eta-expansion of zero-arg methods was deprecated (scala/bug#7187) - 2.13: deprecation dropped in favor of setting the scene for uniform eta-expansion in 3.0 warning still available under -Xlint:eta-zero - 2.14: expected type is a SAM that is not annotated with `@FunctionalInterface` if it's a Java-defined interface (under `-Xlint:eta-sam`) (4.2) condition for auto-application by -Xsource level: - until 2.14: none (assuming condition for (4.3) was not met) - in 3.0: `meth.isJavaDefined` TODO decide -- currently the condition is more involved to give slack to Scala methods overriding Java-defined ones; I think we should resolve that by introducing slack in overriding e.g. a Java-defined `def toString()` by a Scala-defined `def toString`. This also works better for dealing with accessors overriding Java-defined methods. The current strategy in methodSig is problematic: > // Add a () parameter section if this overrides some method with () parameters > val vparamSymssOrEmptyParamsFromOverride = This means an accessor that overrides a Java-defined method gets a MethodType instead of a `NullaryMethodType`, which breaks lots of assumptions about accessors
There's no upside to it. Empty application cannot hurt eta expansion, but eta expansion can hurt empty application.
I propose the order in SLS 6.26.2 place "Empty Application" before "Eta Expansion".
The text was updated successfully, but these errors were encountered: