Skip to content

Commit

Permalink
Fix i18624 and add test case for it (#18859)
Browse files Browse the repository at this point in the history
Addresses #18624.
  • Loading branch information
liufengyun committed Nov 13, 2023
2 parents c81673c + 2e2b223 commit 92a82ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,24 @@ object Objects:

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

case _ =>
// by-name closure
Expand Down
8 changes: 8 additions & 0 deletions tests/init-global/pos/i18624.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def h(a: Int): Unit = {

}

object X {
h.notify()
println(h.getClass())
}

0 comments on commit 92a82ac

Please sign in to comment.