File tree 3 files changed +33
-1
lines changed
compiler/src/dotty/tools/backend/sjs
tests/sjs-junit/test/org/scalajs/testsuite/compiler
3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import Decorators._
18
18
import Flags ._
19
19
import dotty .tools .dotc .ast .Trees ._
20
20
import Names ._
21
+ import NameKinds .DefaultGetterName
21
22
import Types ._
22
23
import Symbols ._
23
24
import Denotations ._
@@ -1069,6 +1070,14 @@ class JSCodeGen()(using genCtx: Context) {
1069
1070
} else if (sym.isJSNativeCtorDefaultParam) {
1070
1071
// #11592
1071
1072
None
1073
+ } else if (sym.is(Bridge ) && sym.name.is(DefaultGetterName ) && currentClassSym.isNonNativeJSClass) {
1074
+ /* #12572 Bridges for default accessors in non-native JS classes must not be emitted,
1075
+ * because they call another default accessor, making their entire body an
1076
+ * <undefined-param> that cannot be eliminated.
1077
+ * Such methods are never called anyway, because they are filtered out in
1078
+ * JSExportsGen.defaultGetterDenot().
1079
+ */
1080
+ None
1072
1081
} else /* if (sym.isClassConstructor && isHijackedBoxedClass(sym.owner)) {
1073
1082
None
1074
1083
} else*/ {
Original file line number Diff line number Diff line change @@ -774,7 +774,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
774
774
else sym.owner
775
775
776
776
private def defaultGetterDenot (targetSym : Symbol , sym : Symbol , paramIndex : Int ): Denotation =
777
- targetSym.info.member (DefaultGetterName (sym.name.asTermName, paramIndex))
777
+ targetSym.info.memberBasedOnFlags (DefaultGetterName (sym.name.asTermName, paramIndex), excluded = Bridge )
778
778
779
779
private def defaultGetterDenot (sym : Symbol , paramIndex : Int ): Denotation =
780
780
defaultGetterDenot(targetSymForDefaultGetter(sym), sym, paramIndex)
Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ class RegressionTestScala3 {
35
35
36
36
assertEquals(5 , foo(5 )(4 ))
37
37
}
38
+
39
+ @ Test def defaultAccessorBridgesIssue12572 (): Unit = {
40
+ new MyPromiseIssue12572 [Int ](5 )
41
+ }
38
42
}
39
43
40
44
object RegressionTestScala3 {
@@ -53,6 +57,25 @@ object RegressionTestScala3 {
53
57
class RangeErrorIssue11592 (msg : String = js.native) extends js.Object {
54
58
val message : String = js.native
55
59
}
60
+
61
+ class MyPromiseIssue12572 [T ](t : T ) extends js.Promise [T ]((resolve, reject) => resolve(t)) {
62
+ override def `then` [S ](
63
+ onFulfilled : js.Function1 [T , S | js.Thenable [S ]],
64
+ onRejected : js.UndefOr [js.Function1 [scala.Any , S | js.Thenable [S ]]] = js.undefined): js.Promise [S ] = {
65
+ ???
66
+ }
67
+
68
+ override def `then` [S >: T ](
69
+ onFulfilled : Unit ,
70
+ onRejected : js.UndefOr [js.Function1 [scala.Any , S | js.Thenable [S ]]]): js.Promise [S ] = {
71
+ ???
72
+ }
73
+
74
+ override def `catch` [S >: T ](
75
+ onRejected : js.UndefOr [js.Function1 [scala.Any , S | js.Thenable [S ]]] = js.undefined): js.Promise [S ] = {
76
+ ???
77
+ }
78
+ }
56
79
}
57
80
58
81
// This class needs to be at the top-level, not in an object, to reproduce the issue
You can’t perform that action at this time.
0 commit comments