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

Internal compiler assertion failure on extension method #13075

Closed
XDracam opened this issue Jul 15, 2021 · 0 comments · Fixed by #13078
Closed

Internal compiler assertion failure on extension method #13075

XDracam opened this issue Jul 15, 2021 · 0 comments · Fixed by #13078

Comments

@XDracam
Copy link

XDracam commented Jul 15, 2021

Compiler version

3.0.1

Minimized code

Hint: when I comment out the reversed method, everything compiles just fine

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 =
    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
    )

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

end Implementing_Tuples

Output (click arrow to expand)

Heavily cropped because the stack trace is quite large

java.lang.AssertionError: assertion failed
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.extensionParam(SymDenotations.scala:341)
	at dotty.tools.dotc.typer.Typer.isLocalExtensionMethodRef$3$$anonfun$2(Typer.scala:524)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.hasAltWith(Denotations.scala:637)
	at dotty.tools.dotc.core.Denotations$MultiDenotation.hasAltWith(Denotations.scala:1251)
	at dotty.tools.dotc.typer.Typer.isLocalExtensionMethodRef$1(Typer.scala:524)
	at dotty.tools.dotc.typer.Typer.typedIdent(Typer.scala:530)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2664)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2943)
	at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:609)
	at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:659)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2665)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2943)
	at dotty.tools.dotc.typer.Applications.tryWithProto$1(Applications.scala:1256)
........
odersky added a commit to dotty-staging/dotty that referenced this issue Jul 15, 2021
Now also finds enclosing methods outside the current class.

Fixes scala#13075
BarkingBad pushed a commit to BarkingBad/dotty that referenced this issue Jul 23, 2021
Now also finds enclosing methods outside the current class.

Fixes scala#13075
@Kordyjan Kordyjan added this to the 3.1.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants