Skip to content

Fix definition of enclosingExtensionMethod #13078

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

Merged
merged 1 commit into from
Jul 16, 2021
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
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1140,11 +1140,10 @@ object SymDenotations {
else NoSymbol

/** The closest enclosing extension method containing this definition,
* provided the extension method appears in the same class.
* including methods outside the current class.
*/
final def enclosingExtensionMethod(using Context): Symbol =
if this.is(ExtensionMethod) then symbol
else if this.isClass then NoSymbol
else if this.exists then owner.enclosingExtensionMethod
else NoSymbol

Expand Down
40 changes: 40 additions & 0 deletions tests/neg/i13075.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
object Implementing_Tuples:

sealed trait Tup
case class ConsTup[T, H <: Tup](head: T, tail: H) extends Tup
case object EmptyTup extends Tup

val *: = ConsTup // for unapply
type *:[H, T <: Tup] = ConsTup[H, T] // for type matching
type EmptyTup = EmptyTup.type // for type matching

extension [H](head: H)
def *:[T <: Tup](tail: T) = ConsTup(head, tail)

type Fold[T <: Tup, Seed, F[_,_]] = T match
case EmptyTup => Seed
case h *: t => Fold[t, F[Seed, h], F]

extension [T <: Tup](v: T)
def fold[Seed, F[_,_]](seed: Seed)(
fn: [C, Acc] => (C, Acc) => F[C, Acc]
): Fold[T, Seed, F] =
(v match
case EmptyTup => seed
case h *: t => t.fold(fn(h, seed))(fn)
).asInstanceOf[Fold[T, Seed, F]]

extension [T <: Tup](v: T) def reversed: Tup =
v.fold[EmptyTup, [C, Acc] =>> Acc match {
case h *: t => C *: h *: t
}](EmptyTup)(
[C, Acc] => (c: C, acc: Acc) => acc match
case _@(_ *: _) => c *: acc // error
)

@main def testProperFold =
val t = (1 *: '2' *: "foo" *: EmptyTup)
val reversed: (String *: Char *: Int *: EmptyTup) = t.reversed // error
println(reversed)

end Implementing_Tuples