Skip to content

Commit 4553799

Browse files
Backport "Fix overloaded default methods test in RefChecks" to LTS (#21078)
Backports #20218 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents db05d86 + bca0d52 commit 4553799

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ object RefChecks {
5151
}}
5252

5353
for (name <- defaultMethodNames) {
54-
val methods = clazz.info.member(name).alternatives.map(_.symbol)
54+
val methods = clazz.thisType.member(name).alternatives.map(_.symbol)
5555
val haveDefaults = methods.filter(_.hasDefaultParams)
5656
if (haveDefaults.length > 1) {
5757
val owners = haveDefaults map (_.owner)

tests/pos/first-class-patterns.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
// Trait of all extractors with unapply methods
3+
trait Matcher[A, B]:
4+
def unapply(x: A): Option[B]
5+
6+
// An extractor defined by an unappy method
7+
object Even extends Matcher[Int, Int]:
8+
def unapply(x: Int): Option[Int] =
9+
if x % 2 == 0 then Some(x) else None
10+
11+
// Method using a given extractor in pattern position
12+
def collect[A, B](xs: List[A], m: Matcher[A, B]): List[B] =
13+
xs match
14+
case Nil => Nil
15+
case m(x) :: xs1 => x :: collect(xs1, m)
16+
case _ :: xs1 => collect(xs1, m)
17+
18+
@main def test =
19+
val xs = List(1, 2, 3, 4)
20+
val ys = collect(xs, Even)
21+
println(ys)
22+
23+

tests/pos/i18555.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait GenericCollectionWithCommands {
2+
self: PackSupport =>
3+
4+
def bar(foo: Int = 1): Any = ???
5+
def bar(writer: GenericCollectionWithCommands.this.pack.Writer[Any]): Any = ???
6+
}
7+
8+
trait PackSupport {
9+
val pack: SerializationPack
10+
}
11+
12+
trait SerializationPack {
13+
type Writer[A]
14+
}

tests/pos/into-bigint.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import language.experimental.into
2+
3+
class BigInt(x: Int):
4+
def + (other: into BigInt): BigInt = ???
5+
def * (other: into BigInt): BigInt = ???
6+
7+
object BigInt:
8+
given Conversion[Int, BigInt] = BigInt(_)
9+
10+
extension (x: into BigInt)
11+
def + (other: BigInt): BigInt = ???
12+
def * (other: BigInt): BigInt = ???
13+
14+
@main def Test =
15+
val x = BigInt(2)
16+
val y = 3
17+
val a1 = x + y
18+
val a2 = y * x
19+
val a3 = x * x
20+
val a4 = y + y
21+

0 commit comments

Comments
 (0)