Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Fix purity check for val inside of object" to LTS #20892

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/run/i17317-b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
12 changes: 12 additions & 0 deletions tests/run/i17317-b.scala
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions tests/run/i17317.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
12 changes: 12 additions & 0 deletions tests/run/i17317.scala
Original file line number Diff line number Diff line change
@@ -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
}
Loading