Skip to content

Compile shows weird message: assertion failed: asTerm called on not-a-Term val <none> #17556

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

Closed
lenguyenthanh opened this issue May 22, 2023 · 2 comments · Fixed by #17570
Closed

Comments

@lenguyenthanh
Copy link

Compiler version

I tested on 3.2.2, 3.3.0-RC6 and 3.nightly

Minimized code

//> using scala 3.2.2

trait FromString[A]:
  def parse(s: String): Either[String, A]

sealed trait Uci:

  case class Move(from: String, to: String) extends Uci

object Uci extends FromString[Uci]:
	def parse(s: String): Either[String, Uci] = ???

or in scastie

Output (click arrow to expand)

Compiling project (Scala 3.2.2, JVM) exception occurred while compiling /Users/tle/git/lichess/scripts/DottyBroke.scala Error compiling project (Scala 3.2.2, JVM) Error: Unexpected error when compiling project_ed944f97cf-10493a1c22: 'assertion failed: asTerm called on not-a-Term val ' Compilation failed

Expect

I expect a better error message.

@lenguyenthanh lenguyenthanh added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels May 22, 2023
@s5bug
Copy link

s5bug commented May 22, 2023

Further minimized:

// must be sealed
// must be trait (not class)
sealed trait A {
  // must be `object` or `case class`
  case class X() extends A
}

// companion object must exist
object A

Note that the above should not throw an error, as the following does not:

sealed trait A {
  case class X() extends A
}

val a = new A {}

a.X()
a.X().X()
a.X().X().X()

@szymon-rd
Copy link
Contributor

szymon-rd commented May 23, 2023

stack trace:

        at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:170)
        at dotty.tools.dotc.transform.ExplicitOuter$.dotty$tools$dotc$transform$ExplicitOuter$$$outerParamAccessor(ExplicitOuter.scala:229)
        at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.loop$1(ExplicitOuter.scala:465)
        at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.path$extension(ExplicitOuter.scala:474)
        at dotty.tools.dotc.transform.Erasure$Typer.typedThis(Erasure.scala:802)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2992)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3054)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3126)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3130)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3242)
        at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$7(Erasure.scala:849)
        at dotty.tools.dotc.core.Decorators$.zipWithConserve(Decorators.scala:155)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:849)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2991)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3054)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
        [...]

@szymon-rd szymon-rd added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 23, 2023
@odersky odersky self-assigned this May 23, 2023
odersky added a commit to dotty-staging/dotty that referenced this issue May 24, 2023
The "ordinal" method generated non-sensical patterns if the cases
of a sealed trait were found in the trait itself. In that case the
ordinal method would be placed in the companion object, but still tried
to access the cases via the `this` of the companion class.

We are  now more careful and fall back to type projections in
comparisons.

Fixes scala#17556
bishabosha added a commit that referenced this issue May 24, 2023
The "ordinal" method generated non-sensical patterns if the cases of a
sealed trait were found in the trait itself. In that case the ordinal
method would be placed in the companion object, but still tried to
access the cases via the `this` of the companion class.

We are now more careful and fall back to type projections in
comparisons.

Fixes #17556
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Kordyjan pushed a commit that referenced this issue Nov 16, 2023
The "ordinal" method generated non-sensical patterns if the cases
of a sealed trait were found in the trait itself. In that case the
ordinal method would be placed in the companion object, but still tried
to access the cases via the `this` of the companion class.

We are  now more careful and fall back to type projections in
comparisons.

Fixes #17556

[Cherry-picked a0be3d6]
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.

5 participants