File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -1239,7 +1239,9 @@ object RefChecks {
12391239 def checkAnyRefMethodCall (tree : Tree )(using Context ) =
12401240 if tree.symbol.exists
12411241 && defn.topClasses.contains(tree.symbol.owner)
1242- && (! ctx.owner.enclosingClass.exists || ctx.owner.enclosingClass.isPackageObject) then
1242+ && (! ctx.owner.enclosingClass.exists
1243+ || ctx.owner.enclosingClass.isPackageObject
1244+ || ctx.owner.enclosingClass.isValueClass) then
12431245 report.warning(UnqualifiedCallToAnyRefMethod (tree, tree.symbol), tree)
12441246
12451247}
Original file line number Diff line number Diff line change 1+ -- [E181] Potential Issue Warning: tests/warn/i17493.scala:3:11 --------------------------------------------------------
2+ 3 | def g = synchronized { println("hello, world") } // warn
3+ | ^^^^^^^^^^^^
4+ | Suspicious top-level unqualified call to synchronized
5+ |---------------------------------------------------------------------------------------------------------------------
6+ | Explanation (enabled by `-explain`)
7+ |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8+ | Top-level unqualified calls to AnyRef or Any methods such as synchronized are
9+ | resolved to calls on Predef or on imported methods. This might not be what
10+ | you intended.
11+ ---------------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change 1+ //> using options -explain
2+ class A (val s : String ) extends AnyVal {
3+ def g = synchronized { println(" hello, world" ) } // warn
4+ }
You can’t perform that action at this time.
0 commit comments