forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scala#15734 from dotty-staging/sjs-new-target
Scala.js: Implement support for js.`new`.target.
- Loading branch information
Showing
5 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.* | ||
|
||
object IllegalInScalaClass { | ||
class A { | ||
js.`new`.target // error: Illegal use of js.`new`.target. | ||
|
||
def this(x: Int) = { | ||
this() | ||
js.`new`.target // error: Illegal use of js.`new`.target. | ||
} | ||
} | ||
|
||
class B { | ||
def foo(x: Int): Unit = | ||
js.`new`.target // error: Illegal use of js.`new`.target. | ||
} | ||
|
||
class C extends js.Object { | ||
class D { | ||
js.`new`.target // error: Illegal use of js.`new`.target. | ||
} | ||
} | ||
} | ||
|
||
object IllegalInDefOrLazyVal { | ||
class A extends js.Object { | ||
lazy val x = js.`new`.target // error: Illegal use of js.`new`.target. | ||
def y: js.Dynamic = js.`new`.target // error: Illegal use of js.`new`.target. | ||
def z(x: Int): Any = js.`new`.target // error: Illegal use of js.`new`.target. | ||
} | ||
} | ||
|
||
object IllegalInLambdaOrByName { | ||
class A extends js.Object { | ||
val x = () => js.`new`.target // error: Illegal use of js.`new`.target. | ||
val y = Option(null).getOrElse(js.`new`.target) // error: Illegal use of js.`new`.target. | ||
val z: js.Function1[Int, Any] = (x: Int) => js.`new`.target // error: Illegal use of js.`new`.target. | ||
val w: js.ThisFunction0[Any, Any] = (x: Any) => js.`new`.target // error: Illegal use of js.`new`.target. | ||
} | ||
} |