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

Fix i18624 and add test case for it #18859

Merged
merged 4 commits into from
Nov 13, 2023
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
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
q-ata marked this conversation as resolved.
Show resolved Hide resolved
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())
}
Loading