Skip to content

Commit 92a82ac

Browse files
authored
Fix i18624 and add test case for it (#18859)
Addresses #18624.
2 parents c81673c + 2e2b223 commit 92a82ac

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

+14-3
Original file line numberDiff line numberDiff line change
@@ -698,13 +698,24 @@ object Objects:
698698

699699
case Fun(code, thisV, klass, env) =>
700700
// meth == NoSymbol for poly functions
701-
if meth.name.toString == "tupled" then
701+
if meth.name == nme.tupled then
702702
value // a call like `fun.tupled`
703703
else
704704
code match
705705
case ddef: DefDef =>
706-
given Env.Data = Env.of(ddef, args.map(_.value), env)
707-
extendTrace(code) { eval(ddef.rhs, thisV, klass, cacheResult = true) }
706+
if meth.name == nme.apply then
707+
given Env.Data = Env.of(ddef, args.map(_.value), env)
708+
extendTrace(code) { eval(ddef.rhs, thisV, klass, cacheResult = true) }
709+
else
710+
// The methods defined in `Any` and `AnyRef` are trivial and don't affect initialization.
711+
if meth.owner == defn.AnyClass || meth.owner == defn.ObjectClass then
712+
value
713+
else
714+
// In future, we will have Tasty for stdlib classes and can abstractly interpret that Tasty.
715+
// For now, return `Cold` to ensure soundness and trigger a warning.
716+
Cold
717+
end if
718+
end if
708719

709720
case _ =>
710721
// by-name closure

tests/init-global/pos/i18624.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def h(a: Int): Unit = {
2+
3+
}
4+
5+
object X {
6+
h.notify()
7+
println(h.getClass())
8+
}

0 commit comments

Comments
 (0)