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

Unit.box and Unit.unbox can no longer be called without a warning #11503

Open
raboof opened this issue Apr 26, 2019 · 6 comments

Comments

Projects
None yet
4 participants
@raboof
Copy link
Member

commented Apr 26, 2019

Because the Unit object now has a @scala.annotation.compileTimeOnly("`Unit` companion object is not allowed in source; instead, use `()` for the unit value")

Should box/unbox utilities be moved somewhere else?

@sjrd

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

There is no need to call those methods, ever. You can always replace Unit.box(x) by x: Any and Unit.unbox(x) by { x ; () }.

@Jasper-M

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

There is no need to call those methods, ever.

If that is the case, wouldn't those methods be better off in scala.runtime? [insert Captain Hindsight meme]

@sjrd

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

Yes, they probably should have been there all along.

@raboof

This comment has been minimized.

Copy link
Member Author

commented Apr 26, 2019

There is no need to call those methods, ever. You can always replace Unit.box(x) by x: Any and Unit.unbox(x) by { x ; () }.

Perhaps deprecate them with that recommendation?

@som-snytt

This comment has been minimized.

Copy link

commented Apr 28, 2019

Either you're invoking the methods reflectively on an AnyValCompanion, or you know statically to use runtime.BoxedUnit. I guess the cast on unboxing can fail, so it's more verbose now; value discard is not equivalent. If the purpose of the boxing methods is Java interop, then it makes sense that Unit.box is not (easily) available, though you can always runtime.BoxedUnit.UNIT.

I think they would need a use case to support "manual unit boxing support."

@som-snytt

This comment has been minimized.

Copy link

commented Apr 28, 2019

A deprecation is probably trumped by the error. There's another issue to say please show me warnings under -Xfatal-warnings aka -Werror even when erroring. But at least the scaladoc would help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.