Skip to content

Commit db31073

Browse files
Merge pull request #13870 from dotty-staging/fix-module-def-default-params-with-bridge
Fix #13860: Ignore bridges when looking for a default getter's attached method.
2 parents 9a855a5 + 025e428 commit db31073

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4706,7 +4706,7 @@ object JSCodeGen {
47064706
if (!overloads.isOverloaded)
47074707
overloads.symbol
47084708
else
4709-
overloads.suchThat(_.is(HasDefaultParams)).symbol
4709+
overloads.suchThat(_.is(HasDefaultParams, butNot = Bridge)).symbol
47104710
}
47114711
}
47124712

tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class RegressionTestScala3 {
5252
def intPlusString(x: String): String = 5 + x
5353
assertEquals("5bc", intPlusString("bc"))
5454
}
55+
56+
@Test def defaultParamsInModuleDefWithBridgesIssue13860(): Unit = {
57+
import Issue13860._
58+
59+
assertEquals(0L, Foo.bar().x)
60+
assertEquals(5L, Foo.bar(5L).x)
61+
}
5562
}
5663

5764
object RegressionTestScala3 {
@@ -100,6 +107,18 @@ object RegressionTestScala3 {
100107
import I._
101108
def blah = i
102109
}
110+
111+
object Issue13860 {
112+
class Foo(var x: Long)
113+
114+
trait Companion[A] {
115+
def bar(x: Long = 0): A
116+
}
117+
118+
object Foo extends Companion[Foo] {
119+
def bar(x: Long = 0): Foo = new Foo(x)
120+
}
121+
}
103122
}
104123

105124
// This class needs to be at the top-level, not in an object, to reproduce the issue

0 commit comments

Comments
 (0)