-
Notifications
You must be signed in to change notification settings - Fork 21
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
SAM types don't work for zero parameter methods #10555
Comments
It's very much intentional that As for the other variant, it works if scala> trait Default[A] { def default(): A }
defined trait Default
scala> (() => ""): Default[String]
res0: Default[String] = $$Lambda$1080/665564874@696db620 This is also as specified: "the method m must have a single argument list" (SLS 6.26.1 again). Whether it was intentional that the no-parameter-lists-at-all case is disallowed by the spec (and by the implementation), I don't know. Offhand, I think it might simply be an oversight. @adriaanm? |
fwiw, |
To me this just adds to the confusion with empty parameter lists:
Seems like whatever you choose you end up with a deprecation or a lint warning. Edit (workaround): trait Default[A] {
protected def leDefault(): A
def default: A = leDefault()
} |
We'll deprecate this in 2.14. Scala 3 will require explicit
Not sure I fully understood the difference between these two cases, but 2.13 will not eta-expand 0-ary methods: scala/scala#6475
Given that SAM is a notion we got from Java, where you cannot define a method without an argument list, I don't think we should allow this. |
(Also note that the main purpose of having no-argument-list methods is to hide the distinction between a |
I guess I meant this: scala> def foo()()() = 42
foo: ()()()Int
scala> foo _
res0: () => () => () => Int = $$Lambda$1053/1955226954@1d8b0500
scala> def bar = 42
bar: Int
scala> bar _
res1: () => Int = $$Lambda$1054/1361755941@515ab3f2 But I totally agree that the recent developments you mentioned are an improvement. |
Glad to hear it, and very grateful for being pushed in the right direction here :-) Keep up the good work! |
Seems like a weak point to me. We get lots of things from Java and extend them. Why "got from Java" should draw the line here.
Why/how would that leak? |
SAM types don't work for methods that don't take params
e.g. this type class
can't have instances defined, e.g.
or
have to do it the old fashioned way
The text was updated successfully, but these errors were encountered: