File tree 3 files changed +18
-1
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -1239,7 +1239,9 @@ object RefChecks {
1239
1239
def checkAnyRefMethodCall (tree : Tree )(using Context ) =
1240
1240
if tree.symbol.exists
1241
1241
&& 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
1243
1245
report.warning(UnqualifiedCallToAnyRefMethod (tree, tree.symbol), tree)
1244
1246
1245
1247
}
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