Skip to content

Regression when compiling scala 2 macro bundle #11415

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
bishabosha opened this issue Feb 15, 2021 · 1 comment · Fixed by #11418
Closed

Regression when compiling scala 2 macro bundle #11415

bishabosha opened this issue Feb 15, 2021 · 1 comment · Fixed by #11418
Assignees
Milestone

Comments

@bishabosha
Copy link
Member

bishabosha commented Feb 15, 2021

This affects the compatibility story for Scala 2 macros, as we can not compile a macro that references a macro bundle

Compiler version

3.0.0-M4-bin-20210214-80befc3-NIGHTLY

Minimized code

package example

import scala.language.experimental.macros

trait Context {

  val universe: Universe

  trait Universe {
    type Tree >: Null <: AnyRef with TreeApi
    type Literal >: Null <: LiteralApi with TermTree
    type TermTree >: Null <: TermTreeApi with Tree

    trait TermTreeApi extends TreeApi { this: TermTree => }
    trait LiteralApi extends TermTreeApi { this: Literal => }
    trait TreeApi extends Product { this: Tree => }
  }
}

object MacroCompat {

  object Bundles {
    def mono: Int = macro Macros2.MacroImpl.mono
    inline def mono: Int = ${ Macros3.monoImpl }
  }

  object Macros2 {
    class MacroImpl(val c: Context) {
      import c.universe._

      def mono: Literal = ???
    }
  }

  object Macros3 {
    import quoted._

    def monoImpl(using Quotes) = '{1}

  }

}

Output (click arrow to expand)

exception occurred while typechecking sandbox/macros/example.scala
exception occurred while compiling sandbox/macros/example.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: example.Context#Universe#LiteralApi &  >: Null <: bundle$1.c.universe.TermTreeApi & bundle$1.c.universe.Tree / TypeRef(TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,module class example)),trait Context),trait Universe),trait LiteralApi) & TypeBounds(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Null),AndType(TypeRef(TermRef(TermRef(TermRef(NoPrefix,val bundle$1),val c),val universe),trait TermTreeApi),TypeRef(TermRef(TermRef(TermRef(NoPrefix,val bundle$1),val c),val universe),type Tree)))
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.core.Types$AndType$.apply(Types.scala:3060)
	at dotty.tools.dotc.core.Types$AndType$.make(Types.scala:3078)
	at dotty.tools.dotc.core.Types$AndType.derivedAndType(Types.scala:3041)
	at dotty.tools.dotc.core.Types$ApproximatingTypeMap.derivedAndType(Types.scala:5504)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5225)
	at dotty.tools.dotc.core.TypeOps$$anon$1.apply(TypeOps.scala:444)
	at dotty.tools.dotc.core.Types$ApproximatingTypeMap.reapply(Types.scala:5552)
	at dotty.tools.dotc.core.Types$ApproximatingTypeMap.expandBounds(Types.scala:5350)
	at dotty.tools.dotc.core.Types$ApproximatingTypeMap.tryWiden(Types.scala:5369)
	at dotty.tools.dotc.core.TypeOps$$anon$1.derivedSelect(TypeOps.scala:459)
	at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5162)
	at dotty.tools.dotc.core.TypeOps$$anon$1.apply(TypeOps.scala:444)
	at dotty.tools.dotc.core.TypeOps$$anon$1.apply(TypeOps.scala:419)
	at dotty.tools.dotc.core.TypeOps$.avoid(TypeOps.scala:469)
	at dotty.tools.dotc.typer.TypeAssigner.avoidingType(TypeAssigner.scala:44)
	at dotty.tools.dotc.typer.TypeAssigner.avoidingType$(TypeAssigner.scala:20)
	at dotty.tools.dotc.typer.Typer.avoidingType(Typer.scala:102)
	at dotty.tools.dotc.typer.TypeAssigner.assignType(TypeAssigner.scala:368)
	at dotty.tools.dotc.typer.TypeAssigner.assignType$(TypeAssigner.scala:20)
	at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:102)
	at dotty.tools.dotc.ast.tpd$.Block(tpd.scala:78)
	at dotty.tools.dotc.typer.Typer.typedPrefix$3$$anonfun$2(Typer.scala:3809)
	at dotty.tools.dotc.typer.Typer.tryAlternatively$$anonfun$3$$anonfun$1(Typer.scala:2865)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2848)
	at dotty.tools.dotc.typer.Typer.tryAlternatively$$anonfun$2(Typer.scala:2868)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2851)
	at dotty.tools.dotc.typer.Typer.tryAlternatively(Typer.scala:2869)
	at dotty.tools.dotc.typer.Typer.typedPrefix$1(Typer.scala:3810)
	at dotty.tools.dotc.typer.Typer.typedScala2MacroBody(Typer.scala:3830)
	at dotty.tools.dotc.typer.Typer.$anonfun$35(Typer.scala:2079)
	at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:223)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2080)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2570)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2654)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2720)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2724)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2746)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2796)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2226)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2581)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2585)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2654)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2720)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2724)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2746)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2796)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2226)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2581)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2585)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2654)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2720)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2724)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2746)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2796)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2378)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2626)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2655)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2720)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2724)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2840)
	at dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
	at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:120)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:120)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:205)
	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:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:215)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:223)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:230)
	at dotty.tools.dotc.Run.compileSources(Run.scala:166)
	at dotty.tools.dotc.Run.compile(Run.scala:150)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
	at dotty.tools.dotc.Driver.process(Driver.scala:186)
	at dotty.tools.dotc.Driver.process(Driver.scala:155)
	at dotty.tools.dotc.Driver.process(Driver.scala:167)
	at dotty.tools.dotc.Driver.main(Driver.scala:194)
	at dotty.tools.dotc.Main.main(Main.scala)
@bishabosha
Copy link
Member Author

I have updated the original post with a reproducible test case that does not require scala-reflect dependency

odersky added a commit that referenced this issue Feb 15, 2021
Fix #11415: always expand bounds in type approximation
@Kordyjan Kordyjan modified the milestones: 3.0.0-RC1, 3.0.0 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.

4 participants