-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Try fix #1786: support use package object as value #1787
Conversation
Does this still prevent val m = scala.meta ? Is there a neg test somewhere against that? |
Thanks @sjrd . We auto convert |
My point is:
|
@liufengyun we already have checks that ensure that java static classes cannot be assigned to variables or passed as arguments. We can use the same infrastructure as restrictions on package are the same. |
If we allow
What if we only do the auto conversion if the package object indeed exists? |
That's precisely what I am against, because it's ultra-inconsistent.
That's not normal. As @DarkDimius pointed out, the same kind of restrictions apply to Java static objects, so hierarchical typing is already broken (and has been since the dawn of time). |
Got it, thanks @sjrd @DarkDimius . I'll update the PR soon. |
I tend to agree with this point of view. What is the motivation for allowing package objects as values? |
Note that I think you can get the package object foo.bar. as a value. That's OK, as this is a real object. By contrast.
is the package, which contains all members of the package object and all members defined in the package. If I write
There's no way that afterwards So I think we should not allow packages which have package objects as values. |
@odersky The motivation is following code:
Of course, scala.meta could define a method I see the argument for against use package object as value. What about just adapt |
ba48e7f
to
e8536f0
Compare
On Tue, Dec 13, 2016 at 3:22 PM, liu fengyun ***@***.***> wrote:
@odersky <https://github.com/odersky> The motivation is following code:
package object meta {
def apply(x: Int): Int = x * x
}
class Test {
def f = meta { 5 + 4 }
}
Of course, scala.meta could define a method def meta(x: Int): Int, but it
doesn't look very nice.
I see the argument for against use package object as value. What about
just adapt foo.bar {...} to foo.bar.package.apply {...} in the context of
application, while disallow other usages?
Yes, I think that's the right thing to do. And it should be easy. In
checkValue, we omit the check if the prototype is a SelectionProto. We
should omit it as well if the prototype is a FunProto or a PolyProto,
because in these cases we will insert an `apply` method later on.
—
… You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1787 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAwlVnVKMtQ_rfpel2AhsPXdgVkrkk0aks5rHqoxgaJpZM4LLtcU>
.
{"api_version":"1.0","publisher":{"api_key":"
05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":
{"external_key":"github/lampepfl/dotty","title":"
lampepfl/dotty","subtitle":"GitHub repository","main_image_url":"
https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-
11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://
cloud.githubusercontent.com/assets/143418/15842166/
7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in
GitHub","url":"https://github.com/lampepfl/dotty"}},"
***@***.*** in #1787:
@odersky The motivation is following code:\r\n\r\n```\r\npackage object
meta {\r\n def apply(x: Int): Int = x * x\r\n}\r\n\r\nclass Test {\r\n def
f = meta { 5 + 4 }\r\n}\r\n```\r\n\r\nOf course, scala.meta could define a
method `def meta(x: Int): Int`, but it doesn't look very nice.\r\n\r\nI see
the argument for against use package object as value. What about just adapt
`foo.bar {...}` to `foo.bar.package.apply {...}` in the context of
application, while disallow other usages?\r\n"}],"action":{"name":"View
Pull Request","url":"https://github.com/lampepfl/dotty/
pull/1787#issuecomment-266750609"}}}
--
Prof. Martin Odersky
LAMP/IC, EPFL
|
e8536f0
to
31337d5
Compare
Thanks for the tip @odersky , that's an incredibly simple fix! It's done now. I didn't notice |
LGTM |
Try fix #1786: support use package object as value.