-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Should Generate warnings when synchronized on AnyVal
#17284
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
AnyVal
AnyVal
That is due to boxing conversion.
The error on Since this ticket is an enhancement, I created a separate issue for the missing error. |
This issue was picked for the Issue Spree No. 32 of 20 June 2023 which takes place in 7 days. @mbovel, @diogocanut, @jmesyou, @michaelpigg will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here. |
I don't know good ressources about autoboxing in Scala, but the one for Java might be worth reading: https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html. |
It's not clear to me what phase of the compiler is relevant to this issue. I was thinking initially the parser, but maybe it's at erasure after the tree shows it converted to a BoxedUnit? |
@michaelpigg, sorry we missed you for this spree! The phase where we added the check is To investigate this issue, we first created a test file at def test = 451.synchronized {} And then printed the AST after the typer using [[syntax trees at end of typer]] // tests/neg/17284.scala
package <empty> {
final lazy module val 17284$package: 17284$package = new 17284$package()
final module class 17284$package() extends Object() {
this: 17284$package.type =>
def test: Unit =
int2Integer(451).synchronized[Unit](
{
()
}
)
}
} We also used the [[syntax trees at end of typer]] // tests/neg/17284.scala
PackageDef(Ident(<empty>), List(
ValDef(17284$package, Ident(17284$package$),
Apply(Select(New(Ident(17284$package$)), <init>), List())),
TypeDef(17284$package$,
Template(DefDef(<init>, List(List()), TypeTree(), Thicket(List())),
List(Apply(Select(New(TypeTree()), <init>), List())),
ValDef(_, SingletonTypeTree(Ident(17284$package)), Thicket(List())), List(
DefDef(test, List(), TypeTree(),
Apply(
TypeApply(
Select(Apply(Ident(int2Integer), List(Literal(451))), synchronized)
,
List(TypeTree())),
List(Block(List(), Literal(()))))
)
))
)
)) And noted that the part we are interested in is More specifically, we're looking for pattern of the form You can find the result of our work in #18021. Don't hesitate to ask if you have questions! I hope to see you at the next Spree. |
Thanks for the explanation, @mbovel ! |
Compiler version
3.2.2
Minimized code
Output
Expectation
generate some warning as https://openjdk.org/jeps/390
The text was updated successfully, but these errors were encountered: