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 @@ -1157,7 +1157,9 @@ object RefChecks {
1157
1157
def checkAnyRefMethodCall (tree : Tree )(using Context ) =
1158
1158
if tree.symbol.exists
1159
1159
&& defn.topClasses.contains(tree.symbol.owner)
1160
- && (! ctx.owner.enclosingClass.exists || ctx.owner.enclosingClass.isPackageObject) then
1160
+ && (! ctx.owner.enclosingClass.exists
1161
+ || ctx.owner.enclosingClass.isPackageObject
1162
+ || ctx.owner.enclosingClass.isValueClass) then
1161
1163
report.warning(UnqualifiedCallToAnyRefMethod (tree, tree.symbol), tree)
1162
1164
1163
1165
}
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