Skip to content

Dottydoc fails to read symbol in scalajs project on RC2 #11943

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

Closed
djspiewak opened this issue Mar 30, 2021 · 15 comments
Closed

Dottydoc fails to read symbol in scalajs project on RC2 #11943

djspiewak opened this issue Mar 30, 2021 · 15 comments

Comments

@djspiewak
Copy link

[error] -- Error: kernel/js/src/main/scala/cats/effect/kernel/AsyncPlatform.scala:38:8 -
[error] 38 |        p.`then`[Unit](onFulfilled, defined(onRejected))
[error]    |        ^^^^^^^^^^^^^
[error]    |undefined: p.then # -1: TermRef(TermRef(NoPrefix,val p),then) at readTasty

Not very minimized, sorry. Here is the exact line and commit hash: https://github.com/typelevel/cats-effect/blob/dedfedecf843e4272488eeaa71581d64eeb08194/kernel/js/src/main/scala/cats/effect/kernel/AsyncPlatform.scala#L38 This compiles and runs just fine on 2.12, 2.13, RC1, and RC2. However, when I attempt to run sbt doc, it errors here.

@griggt
Copy link
Contributor

griggt commented Mar 30, 2021

Without cats-effect:

import scala.scalajs.js.{|, defined, Function1, Promise, Thenable}

trait Foo {
  def bar[A](p: Promise[A]) = {
    val onFulfilled: Function1[A, Unit | Thenable[Unit]] = ???
    val onRejected: Function1[Any, Unit | Thenable[Unit]] = ???
    p.`then`[Unit](onFulfilled, defined(onRejected))
  }
}

Seems to have been working before #11671

@VlachJosef
Copy link

Same problem is happening in playframework/play-json#590

[error] -- Error: play-json/js/src/main/scala/StaticBinding.scala:118:25 --------------------------------------------------------------------------------------------
[error] 118 |    if (!escapeNonASCII) JSON.stringify(s) else escapeStr(JSON.stringify(s))
[error]     |                         ^^^^^^^^^^^^^^^^
[error]     |undefined: scala.scalajs.js.JSON.stringify # -1: TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class scalajs)),object js),JSON),stringify) at readTasty
...
[error] (play-jsonJS / Compile / doc) DottyDoc Compilation Failed

Workaround there was to provide missing argument for JSON.stringify(s, null)

@yurique
Copy link

yurique commented Apr 3, 2021

I'm getting a very similar error in this file: https://github.com/tulz-app/frontroute/blob/5cd37701c6203cf1a6679960cf17f2f63f114bf3/src/main/scala/io/frontroute/RouteLocation.scala
(https://github.com/tulz-app/frontroute/runs/2260870881?check_suite_focus=true)

[error] -- Error: src/main/scala/io/frontroute/RouteLocation.scala:35:4 ----------------
[error] 35 |    RouteLocation(
[error]    |    ^
[error]    |undefined: io.frontroute.RouteLocation.apply # -1: TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class io)),object frontroute),object RouteLocation),apply) at readTasty
[error] 36 |      hostname = location.hostname,
[error] 37 |      port = location.port,
[error] 38 |      protocol = location.protocol,
[error] 39 |      host = location.host,
[error] 40 |      origin = location.origin.toOption,
[error] 41 |      unmatchedPath = extractPath(location),
[error] 42 |      params = LocationUtils.parseLocationParams(location),
[error] 43 |      state = state

A workaround for me was to change line 35 to be new RouteLocation( instead of RouteLocation(.

@griggt
Copy link
Contributor

griggt commented Apr 3, 2021

Standalone simpler version of the above:

import scala.scalajs.js

final case class RouteLocation(loc: String, state: js.UndefOr[js.Any])

object RouteLocation:
  def apply(loc: String): RouteLocation = RouteLocation(loc, js.undefined)

@pikinier20
Copy link
Contributor

I've tried to compile @djspiewak problematic project from tasty with command:

./scalac -classpath /home/fzybala/scala3bench/cats-effect-series-3.x/kernel/js/target/scala-3.0.0-RC3/classes:/home/fzybala/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-core_sjs1_3.0.0-RC3/2.6.0/cats-core_sjs1_3.0.0-RC3-2.6.0.jar -from-tasty /home/fzybala/scala3bench/cats-effect-series-3.x/kernel/js/target/scala-3.0.0-RC3/classes/cats/effect/kernel/AsyncPlatform.tasty 

And got following error log:

-- Error: kernel/js/src/main/scala/cats/effect/kernel/AsyncPlatform.scala:38:8 -
undefined: p.then # -1: TermRef(TermRef(NoPrefix,val p),then) at readTasty
-- Error: kernel/js/src/main/scala/cats/effect/kernel/AsyncPlatform.scala:38:36 
undefined: scala.scalajs.js.defined.apply # -1: TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class scalajs)),object js),defined),apply) at readTasty
-- Error: kernel/js/src/main/scala/cats/effect/kernel/AsyncPlatform.scala:32:22 
undefined: scala.scalajs.js.JavaScriptException.apply # -1: TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class scalajs)),object js),JavaScriptException),apply) at readTasty
3 errors found

So for me it looks like it's not directly related to doctool but TASTY file is invalid and causes errors when you try to compile from tasty.

@smarter
Copy link
Member

smarter commented Apr 30, 2021

undefined: scala.scalajs.js.defined.apply

Looks like you're compiling without the scala.js standard library on the classpath.

@pikinier20
Copy link
Contributor

You're right, I've added js library on classpath, but still I get errors

./scalac -classpath /home/fzybala/scala3bench/cats-effect-series-3.x/kernel/js/target/scala-3.0.0-RC3/classes:/home/fzybala/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-core_sjs1_3.0.0-RC3/2.6.0/cats-core_sjs1_3.0.0-RC3-2.6.0.jar::/home/fzybala/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-library_2.13/1.5.1/scalajs-library_2.13-1.5.1.jar:/home/fzybala/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_sjs1_3.0.0-RC3/3.0.0-RC3/scala3-library_sjs1_3.0.0-RC3-3.0.0-RC3.jar -from-tasty /home/fzybala/scala3bench/cats-effect-series-3.x/kernel/js/target/scala-3.0.0-RC3/classes/cats/effect/kernel/AsyncPlatform.tasty 
-- Error: kernel/js/src/main/scala/cats/effect/kernel/AsyncPlatform.scala:38:8 -
undefined: p.then # -1: TermRef(TermRef(NoPrefix,val p),then) at readTasty
1 error found

@smarter
Copy link
Member

smarter commented Apr 30, 2021

No idea what's going on but you probably also need -scalajs.

@pikinier20
Copy link
Contributor

Actually I've tried to use -scalajs flag but with this flag included I've got an exception with very long stacktrace: https://pastebin.com/CgFw5tu8
I also noticed that cats-effect use lib: scalajs-library_2.13-1.5.1.jar which looks like it's compiled with 2.13 and apparently this one is causing exception. Removing this lib from classpath while still using -scalajs flag takes us back to my first error log (3 errors)

@smarter
Copy link
Member

smarter commented Apr 30, 2021

scalajs-library_2.13-1.5.1.jar which looks like it's compiled with 2.13

Yes, that's normal, there's no Scala 3 version of scalajs-library and Scala 3 Scala.js projects always depend on the 2.13 version.

@smarter
Copy link
Member

smarter commented May 23, 2021

For anyone landing here: the fix for this issue requires a new sbt release (sbt/sbt#6499), meanwhile you can disable scaladoc generation on scala 3 to work around the problem:

Compile / doc / sources := {
  if (scalaVersion.value.startsWith("3"))
    Seq() // disabled to work around https://github.com/lampepfl/dotty/issues/11943
  else
    (Compile / doc / sources).value
}

@sjrd
Copy link
Member

sjrd commented Jun 1, 2021

Is this fixed when using sbt 1.5.3 then? (it was released today and seems to include the PR you linked to)

@AugustNagro
Copy link
Contributor

@sjrd I tried 1.5.3 and have the same error:

undefined: scala.scalajs.js.JSON.stringify # -1: TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class scalajs)),object js),JSON),stringify) at readTasty

@smarter
Copy link
Member

smarter commented Jun 1, 2021

You need to try it with a nightly of the compiler too (scalaVersion := "3.0.1-RC1-bin-20210531-fa36577-NIGHTLY")

@smarter
Copy link
Member

smarter commented Jun 9, 2021

Closing since this should be fixed in 3.0.1-RC1 / sbt 1.5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants