diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index dfa685f8aaa9..6afce2ff2aa0 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -1173,7 +1173,7 @@ class Objects(using Context @constructorOnly): case v @ SafeValue(_) => if v.typeSymbol != defn.NullClass then - // selection on Null is sensible on AST level; no warning for it + // selection on Null is sensible on AST level but not in practice report.warning("[Internal error] Unexpected selection on safe value " + v.show + ", field = " + field.show + ". " + Trace.show, Trace.position) end if Bottom @@ -1573,7 +1573,13 @@ class Objects(using Context @constructorOnly): val target = expr.tpe.widenSingleton.classSymbol.asClass withTrace(trace2) { resolveThis(target, qual.asInstanceOf[ThisValue], klass) } case _ => - withTrace(trace2) { select(qual, expr.symbol, receiver = qualifier.tpe) } + qual match { + // Check if expression is a selection of a method + case v: SafeValue if expr.symbol.is(Flags.Method) => + withTrace(trace2) { call(v, expr.symbol, args = Nil, receiver = qualifier.tpe, superType = NoType) } + case _ => + withTrace(trace2) { select(qual, expr.symbol, receiver = qualifier.tpe) } + } case _: This => evalType(expr.tpe, thisV, klass) diff --git a/tests/init-global/pos-tasty/test-safe-value.scala b/tests/init-global/pos-tasty/test-safe-value.scala new file mode 100644 index 000000000000..cb5149864216 --- /dev/null +++ b/tests/init-global/pos-tasty/test-safe-value.scala @@ -0,0 +1,7 @@ +package scala.collection.immutable + +object A { // These are a safe values, so no warning should be emitted + Node.HashCodeLength + Node.BitPartitionSize + Node.MaxDepth +} \ No newline at end of file