Skip to content

Commit 36323a4

Browse files
committed
Purity of primary constructor calls
Calls to primary constructors of NoInits classes are pure if prefix and arguments are pure.
1 parent 58d8e71 commit 36323a4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
399399
case Apply(fn, args) =>
400400
def isKnownPureOp(sym: Symbol) =
401401
sym.owner.isPrimitiveValueClass || sym.owner == defn.StringClass
402-
if (tree.tpe.isInstanceOf[ConstantType] && isKnownPureOp(tree.symbol)
403-
// A constant expression with pure arguments is pure.
404-
|| fn.symbol.isStable)
402+
if (tree.tpe.isInstanceOf[ConstantType] && isKnownPureOp(tree.symbol) // A constant expression with pure arguments is pure.
403+
|| fn.symbol.isStable
404+
|| fn.symbol.isPrimaryConstructor && fn.symbol.owner.isNoInitsClass) // TODO: include in isStable?
405405
minOf(exprPurity(fn), args.map(exprPurity)) `min` Pure
406406
else if (fn.symbol.is(Erased)) Pure
407407
else Impure

0 commit comments

Comments
 (0)