question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

inlined given resulting in runtime error java.lang.NoSuchFieldError: $outer

See original GitHub issue

Compiler version

v3.0.2-RC1 (also tried on master branch)

Minimized code

trait DFC
given DFC = new DFC {}

trait TC
object TC:
  def foo()(using DFC): Unit = {}

  inline given (using DFC): TC = new TC:
    foo()

class Foo(using DFC):
  summon[TC]

val top = new Foo

Output

See scastie: https://scastie.scala-lang.org/yZG6miffRf6f4O6od68i2w

java.lang.NoSuchFieldError: $outer
	at Playground$$anon$2.<init>(main.scala:11)
	at Playground$Foo.<init>(main.scala:11)
	at Playground$.<clinit>(main.scala:16)
	at Main$.<clinit>(main.scala:20)
	at Main.main(main.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sbt.Run.invokeMain(Run.scala:133)
	at sbt.Run.execute$1(Run.scala:82)
	at sbt.Run.$anonfun$runWithLoader$5(Run.scala:110)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:17)
	at sbt.TrapExit$App.run(TrapExit.scala:258)
	at java.lang.Thread.run(Thread.java:748)

Expectation

No runtime error.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, Dec 10, 2021

It seems inlining local classes has lots of problems. Can we outlaw it completely?

0reactions
oderskycommented, Feb 25, 2022

After #14568 the “bad type problem” is fixed. But we now get a new problem for the original code from @soronpo:

*** error while checking i13334a.scala after phase inlining ***
exception occurred while compiling i13334a.scala
java.lang.AssertionError: assertion failed: wrong source set for Baz.this.x$1 # -1 of class dotty.tools.dotc.ast.Trees$Select, set to library/src/scala/runtime/stdLibPatches/Predef.scala but context had i13334a.scala
 private[this] <paramaccessor> <synthetic> given <touched> while compiling i13334a.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: wrong source set for Baz.this.x$1 # -1 of class dotty.tools.dotc.ast.Trees$Select, set to library/src/scala/runtime/stdLibPatches/Predef.scala but context had i13334a.scala

I verified that the same error occurs even without #14568 if we disable the “bad type problem” check.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Resolve the NoSuchFieldError in Java
The NoSuchFieldError error occurs if an application tries to access or modify a specified field of an object, and the object no longer...
Read more >
debugging - NoSuchFieldError Java
When I try to access the field m_metatable in 'Part' I get this error, which is odd since the field ins't accessed a...
Read more >
RuntimeException
java.util.concurrent ... DirectoryIteratorException, Runtime exception thrown if an I/O error is encountered when iterating over the entries in a directory.
Read more >
NoSuchFieldError in Java
Finally, LinkageError extends Error and shows that a class has some dependency on another incompatibly changed class.
Read more >
aosp/platform/external/libchrome
-12,9 +12,10 @@ # See the License for the specific language ... So for others - // tcmalloc will give a general error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found