From 9e7109566f0c3b9e75cca7fe7f9e882e7b63873b Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Mon, 17 Oct 2022 13:41:11 +0200 Subject: [PATCH] Avoid checking purity of Apply without symbols closes #16174 --- compiler/src/dotty/tools/dotc/ast/TreeInfo.scala | 2 +- tests/pos/i16174.scala | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i16174.scala diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 083a92b26d11..97e7b70ce890 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -512,7 +512,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => sym.owner.isPrimitiveValueClass || sym.owner == defn.StringClass || defn.pureMethods.contains(sym) - tree.tpe.isInstanceOf[ConstantType] && isKnownPureOp(tree.symbol) // A constant expression with pure arguments is pure. + 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 /** The purity level of this reference. diff --git a/tests/pos/i16174.scala b/tests/pos/i16174.scala new file mode 100644 index 000000000000..7126fcf7369a --- /dev/null +++ b/tests/pos/i16174.scala @@ -0,0 +1,3 @@ +val f = [A] => (a: A) => a +val x1 = f.apply[Int](4) +val x2 = f.apply[4](4)