Skip to content

Quotes can crash due to missing implicit type instance in local function #15985

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
WojciechMazur opened this issue Sep 7, 2022 · 1 comment · Fixed by #16345
Closed

Quotes can crash due to missing implicit type instance in local function #15985

WojciechMazur opened this issue Sep 7, 2022 · 1 comment · Fixed by #16345
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

Regression reproduced based on the failure in Open CB #4763. Problem found in playframework/anorm

Compiler version

Fails in 3.2.1-RC1
Fails in 3.2.0
Works in 3.1.3

Minimized code

package anorm.macros
sealed trait Row
sealed trait SqlResult[A]

import scala.quoted.{ Expr, Quotes, Type }

private[anorm] object RowParserImpl {
  def apply[A](using q:Quotes)(using Type[A]): Expr[Row => SqlResult[A]] = {
    import q.reflect.*

    inline def fails: Expr[SqlResult[A]] =
      Match(???, ???).asExprOf[SqlResult[A]] 
    
    // Workarounds:
    inline def compiles(using Type[SqlResult[A]]): Expr[SqlResult[A]] =
      Match(???, ???).asExprOf[SqlResult[A]] 

    // Compiles
    Match(???, ???).asExprOf[SqlResult[A]] 
    ???
  }
}

Output (click arrow to expand)

exception occurred while compiling test.scala
java.lang.AssertionError: assertion failed while compiling test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
        at dotty.tools.dotc.ast.TypedTreeInfo.constToLiteral(TreeInfo.scala:565)
        at dotty.tools.dotc.ast.TypedTreeInfo.constToLiteral$(TreeInfo.scala:387)
        at dotty.tools.dotc.ast.tpd$.constToLiteral(tpd.scala:23)
        at dotty.tools.dotc.transform.FirstTransform.transformBlock(FirstTransform.scala:174)
        at dotty.tools.dotc.transform.MegaPhase.goBlock(MegaPhase.scala:740)
        at dotty.tools.dotc.transform.MegaPhase.transformBlock(MegaPhase.scala:450)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:298)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:459)
        at dotty.tools.dotc.transform.MegaPhase.transformTrees(MegaPhase.scala:459)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:303)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:278)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:459)
        at dotty.tools.dotc.transform.MegaPhase.transformTrees(MegaPhase.scala:459)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:279)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:320)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:248)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
        at dotty.tools.dotc.transform.MegaPhase.loop$2(MegaPhase.scala:444)
        at dotty.tools.dotc.transform.MegaPhase.transformBlock(MegaPhase.scala:449)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:298)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:248)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
        at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:438)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:438)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:255)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
        at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:438)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:438)
        at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:379)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:382)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:454)
        at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:466)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:311)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:312)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:234)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:245)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:253)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:262)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:262)
        at dotty.tools.dotc.Run.compileSources(Run.scala:186)
        at dotty.tools.dotc.Run.compile(Run.scala:170)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.MainGenericCompiler$.run$1(MainGenericCompiler.scala:162)
        at dotty.tools.MainGenericCompiler$.main(MainGenericCompiler.scala:186)
        at dotty.tools.MainGenericCompiler.main(MainGenericCompiler.scala)
        ```
</details>
@WojciechMazur WojciechMazur added itype:bug itype:crash regression This worked in a previous version but doesn't anymore stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 7, 2022
@mbovel mbovel added area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 9, 2022
@odersky
Copy link
Contributor

odersky commented Oct 3, 2022

Can we get a bisect of this one?

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 15, 2022
Remove contents of inline methods when pickling quotes in case these contain
quoted expressions or types. Some artifacts of staging (such as type blocks)
are not handled by the transformation phases that follow.

Fixes scala#15985
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 15, 2022
Remove contents of inline methods when pickling quotes in case these contain
quoted expressions or types. Some artifacts of staging (such as type blocks)
are not handled by the transformation phases that follow.

Fixes scala#15985
@nicolasstucki nicolasstucki self-assigned this Nov 15, 2022
@Kordyjan Kordyjan modified the milestones: Future versions, 3.3.0-RC1 Dec 12, 2022
smarter added a commit that referenced this issue Dec 12, 2022
Remove contents of inline methods when pickling quotes in case these
contain quoted expressions or types. Some artifacts of staging (such as
type blocks) are not handled by the transformation phases that follow.

Fixes #15985
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
Remove contents of inline methods when pickling quotes in case these contain
quoted expressions or types. Some artifacts of staging (such as type blocks)
are not handled by the transformation phases that follow.

Fixes scala#15985
@Kordyjan Kordyjan modified the milestones: 3.3.0-RC1, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants