Skip to content
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

Fix overloaded default methods test in RefChecks #20218

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object RefChecks {
}}

for (name <- defaultMethodNames) {
val methods = clazz.info.member(name).alternatives.map(_.symbol)
val methods = clazz.thisType.member(name).alternatives.map(_.symbol)
val haveDefaults = methods.filter(_.hasDefaultParams)
if (haveDefaults.length > 1) {
val owners = haveDefaults map (_.owner)
Expand Down
23 changes: 23 additions & 0 deletions tests/pos/first-class-patterns.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

// Trait of all extractors with unapply methods
trait Matcher[A, B]:
def unapply(x: A): Option[B]

// An extractor defined by an unappy method
object Even extends Matcher[Int, Int]:
def unapply(x: Int): Option[Int] =
if x % 2 == 0 then Some(x) else None

// Method using a given extractor in pattern position
def collect[A, B](xs: List[A], m: Matcher[A, B]): List[B] =
xs match
case Nil => Nil
case m(x) :: xs1 => x :: collect(xs1, m)
case _ :: xs1 => collect(xs1, m)

@main def test =
val xs = List(1, 2, 3, 4)
val ys = collect(xs, Even)
println(ys)


14 changes: 14 additions & 0 deletions tests/pos/i18555.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trait GenericCollectionWithCommands {
self: PackSupport =>

def bar(foo: Int = 1): Any = ???
def bar(writer: GenericCollectionWithCommands.this.pack.Writer[Any]): Any = ???
}

trait PackSupport {
val pack: SerializationPack
}

trait SerializationPack {
type Writer[A]
}
21 changes: 21 additions & 0 deletions tests/pos/into-bigint.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import language.experimental.into

class BigInt(x: Int):
def + (other: into BigInt): BigInt = ???
def * (other: into BigInt): BigInt = ???

object BigInt:
given Conversion[Int, BigInt] = BigInt(_)

extension (x: into BigInt)
def + (other: BigInt): BigInt = ???
def * (other: BigInt): BigInt = ???

@main def Test =
val x = BigInt(2)
val y = 3
val a1 = x + y
val a2 = y * x
val a3 = x * x
val a4 = y + y

Loading