diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 5ded0e1262e4..28d3ef6daaef 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -578,8 +578,9 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => sym.owner.isPrimitiveValueClass || sym.owner == defn.StringClass || defn.pureMethods.contains(sym) + tree.tpe.isInstanceOf[ConstantType] && tree.symbol != NoSymbol && isKnownPureOp(tree.symbol) // A constant expression with pure arguments is pure. - || fn.symbol.isStableMember && !fn.symbol.is(Lazy) // constructors of no-inits classes are stable + || fn.symbol.isStableMember && fn.symbol.isConstructor // constructors of no-inits classes are stable /** The purity level of this reference. * @return diff --git a/tests/run/i17317-b.check b/tests/run/i17317-b.check new file mode 100644 index 000000000000..3b18e512dba7 --- /dev/null +++ b/tests/run/i17317-b.check @@ -0,0 +1 @@ +hello world diff --git a/tests/run/i17317-b.scala b/tests/run/i17317-b.scala new file mode 100644 index 000000000000..b1606da6df20 --- /dev/null +++ b/tests/run/i17317-b.scala @@ -0,0 +1,12 @@ +object foo { + object HelloGen { + println("hello world") + } + val Hello = HelloGen +} + +import foo.Hello + +object Test { + def main(args: Array[String]): Unit = Hello: Unit +} diff --git a/tests/run/i17317.check b/tests/run/i17317.check new file mode 100644 index 000000000000..3b18e512dba7 --- /dev/null +++ b/tests/run/i17317.check @@ -0,0 +1 @@ +hello world diff --git a/tests/run/i17317.scala b/tests/run/i17317.scala new file mode 100644 index 000000000000..41ea627c20b9 --- /dev/null +++ b/tests/run/i17317.scala @@ -0,0 +1,12 @@ +package object foo { + object HelloGen { + println("hello world") + } + val Hello = HelloGen +} + +import foo.Hello + +object Test { + def main(args: Array[String]): Unit = Hello: Unit +}