Binding.scala icon indicating copy to clipboard operation
Binding.scala copied to clipboard

Scala.JS: Cannot call lookupMethod(init___sc_Seq) on non Scala class sjs_js_Function

Open pme123 opened this issue 7 years ago • 12 comments

I ran in a strange behavior, that I describe here: https://stackoverflow.com/questions/50269126/scala-js-cannot-call-lookupmethodinit-sc-seq-on-non-scala-class-sjs-js-func

According to the comment of the creator of Scala.js that might be a bug in Binding.scala

pme123 avatar May 11 '18 07:05 pme123

Could you make the bug report be minimized and reproducible?

Atry avatar May 11 '18 07:05 Atry

Yes - as described - in Stackoverflow.

I created a branch: https://github.com/pme123/scala-adapters/tree/binding-issue-78

Master branch with a 'shorter' name works.

pme123 avatar May 11 '18 08:05 pme123

Maybe it's reproducible, but still far from minimized. It would be easier to find the cause if it is minimized.

Atry avatar May 11 '18 10:05 Atry

Also adding a -Xprint:typer flag should help if you want to investigate it.

Atry avatar May 11 '18 10:05 Atry

As it works now for me (Using shorter class name) - it is not so high in the priority list anymore. If I get some time I will try to minimize it.

pme123 avatar May 11 '18 11:05 pme123

@sjrd How do you think?

Atry avatar May 11 '18 14:05 Atry

The relevant output from -Xprint:typer would be critical to evaluate this. And perhaps -Xprint:mixin as well. Also, the output of scalajsp the/problematic/Class.sjsir could be useful too.

sjrd avatar May 11 '18 15:05 sjrd

I tried to minimize the project - without success - a basic project with a case class that has a long name was not failing.

Then I did what @sjrd suggested. These created huge logs that I added to a gist:

https://gist.github.com/pme123/aadcc0fd101f6f7cf81e62f6f43d4fa1

    1. log is with -Xprint:typer
    1. log is with -Xprint:mixin
    1. log is with scalajsp

The long class is called: DemoWithLongerNameRunJobDialog

pme123 avatar May 15 '18 09:05 pme123

I think the relevant code and logs are:

https://github.com/pme123/scala-adapters/blob/063b9e8/client/src/main/scala/pme123/adapters/client/demo/DemoRunJobDialog.scala#L83

    final <artifact> def $anonfun$demoForm$140(x$3: org.scalajs.dom.raw.UIEvent, demoDescr$1: org.scalajs.dom.raw.HTMLInputElement, reader$1: org.scalajs.dom.raw.FileReader): Unit = DemoWithLongerNameRunJobDialog.this.socket().runAdapter(new Some(play.api.libs.json.Json.toJson(new pme123.adapters.shared.demo.ImageUpload(demoDescr$1.value(), new StringContext(scala.Predef.wrapRefArray(Array[String]{"", ""}.$asInstanceOf[Array[Object]]())).s(scala.Predef.genericWrapArray(Array[Object]{reader$1.result()}))), demo.this.ImageUpload.jsonFormat())));
  def pme123$adapters$client$demo$DemoWithLongerNameRunJobDialog$$$anonfun$demoForm$140__Lorg_scalajs_dom_raw_UIEvent__Lorg_scalajs_dom_raw_HTMLInputElement__Lorg_scalajs_dom_raw_FileReader__V(x$3: any, demoDescr$1: any, reader$1: any) {
    this.socket__Lpme123_adapters_client_ClientWebsocket().runAdapter__s_Option__V(new s_Some().init___O(mod:Lplay_api_libs_json_Json$.toJson__O__Lplay_api_libs_json_Writes__Lplay_api_libs_json_JsValue(new Lpme123_adapters_shared_demo_ImageUpload().init___T__T(demoDescr$1["value"].asInstanceOf[T], new s_StringContext().init___sc_Seq(new sjs_js_WrappedArray().init___sjs_js_Array(["", ""])).s__sc_Seq__T(new sjs_js_WrappedArray().init___sjs_js_Array([reader$1["result"]]))), mod:Lpme123_adapters_shared_demo_ImageUpload$.jsonFormat__Lplay_api_libs_json_OFormat())))
  }

Atry avatar May 15 '18 09:05 Atry

@pme123 The init___sc_Seq is actually the constructor of StringContext (used for string interpolation). I don't think your StackOverflow code will cause this error, considering your StackOverflow code does not use string interpolation at all.

Atry avatar May 15 '18 09:05 Atry

As described in the Stackoverflow question:

If I comment /*reader.onload = (_: UIEvent) => ... } */ it works.

It doesn't matter what is in the onload function. I tried empty, println("hello")

pme123 avatar May 15 '18 10:05 pme123

Interesting... I used to think that other expressions like println would not create init___sc_Seq.

Atry avatar May 15 '18 10:05 Atry