Skip to content

Unit JS default param makes compiler crash with "Found a dangling UndefinedParam" #4684

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
armanbilge opened this issue Jun 11, 2022 · 6 comments
Assignees
Labels
bug Confirmed bug. Needs to be fixed.
Milestone

Comments

@armanbilge
Copy link
Member

//> using scala "2.13.8"
//> using platform "js"

package foo

import scala.scalajs.js

@js.native
trait Bar extends js.Object {
  protected[foo] def baz(
    dummy: Unit = js.native,
  ): Unit = js.native
}

object App {

  def bar: Bar = ???

  def main = bar.baz()

}
[error] ./bug.scala:15:1: Found a dangling UndefinedParam at Position(file:/workspace/sandbox/bug.scala,18,17). This is likely due to a bad interaction between a macro or a compiler plugin and the Scala.js compiler plugin. If you hit this, please let us know.

Scala 3 sibling issue:

@armanbilge armanbilge changed the title Found a dangling UndefinedParam package-protected method errors with "Found a dangling UndefinedParam" Jun 11, 2022
@armanbilge armanbilge changed the title package-protected method errors with "Found a dangling UndefinedParam" package-protected facade method errors with "Found a dangling UndefinedParam" Jun 11, 2022
@gzm0
Copy link
Contributor

gzm0 commented Jun 11, 2022

I can reproduce this on all major Scala versions. Thank you for the report.

@gzm0 gzm0 added the bug Confirmed bug. Needs to be fixed. label Jun 11, 2022
@gzm0
Copy link
Contributor

gzm0 commented Jun 11, 2022

Note: Package private is not required. Plain old public method also causes the issue.

@armanbilge
Copy link
Member Author

Interesting, it may have been needed for my Scala 3 reproduction since that's where I started from.

@gzm0
Copy link
Contributor

gzm0 commented Jun 11, 2022

I think the issue is the Unit value: The generated IR that crashes is:

def main;V() {
  val qual$1: any = this.bar;Lhelloworld.Bar();
  val x$1: java.lang.Void = {
    <undefined-param>;
    (void 0)
  };
  qual$1["baz"](x$1)
}

@gzm0
Copy link
Contributor

gzm0 commented Jun 11, 2022

FWIW: Indeed changing the argument type to Int makes the issue vanish.

@gzm0 gzm0 changed the title package-protected facade method errors with "Found a dangling UndefinedParam" Unit JS default param makes compiler crash with "Found a dangling UndefinedParam" Jun 11, 2022
@sjrd
Copy link
Member

sjrd commented Jun 11, 2022

Ouch. I guess the scalac (and dotc) tree that comes right before that is

val x$1: BoxedUnit$ = {
  qual$1.baz$default$1();
  BoxedUnit$.UNIT
}

We could recognize that shape and collapse it to a single <undefined-param>, but we might be too broad and get false positives with that. Then again, if we don't catch that shape and it's present, it is going to crash anyway instead, so perhaps that's fine.

@sjrd sjrd added this to the v1.10.1 milestone Jun 12, 2022
@sjrd sjrd self-assigned this Jun 12, 2022
@sjrd sjrd closed this as completed in 1de54d7 Jun 13, 2022
sjrd added a commit that referenced this issue Jun 13, 2022
Fix #4684: Handle Unit parameters with default values in JS types.
sjrd added a commit to sjrd/scala-js that referenced this issue Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug. Needs to be fixed.
Projects
None yet
Development

No branches or pull requests

3 participants