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

language features fail to be found during mixin #7240

Closed
scabug opened this issue Mar 11, 2013 · 2 comments
Closed

language features fail to be found during mixin #7240

scabug opened this issue Mar 11, 2013 · 2 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Mar 11, 2013

package bakery

import scala.language.experimental.macros
import scala.reflect.macros.Context

trait FailureCake {
  implicit def liftAnyFails[T: Manifest]: Any = ???

  // This works
  // implicit def liftAny[T]: Any = ???
}

object Bakery {

  def failure: Any = macro failureImpl
  def failureImpl(c: Context): c.Expr[Any] = {
    import c.universe._

    def dslTrait(dslName: String) = {
      val names = dslName.split("\\.").toList.reverse
      assert(names.length >= 1, "DSL trait name must be in the valid format. DSL trait name is " + dslName)

      val tpeName = newTypeName(names.head)
      names.tail.reverse match {
        case head :: tail 
          Select(tail.foldLeft[Tree](Ident(newTermName(head)))((tree, name)  Select(tree, newTermName(name))), tpeName)
        case Nil 
          Ident(tpeName)
      }
    }

    def composeDSL(transformedBody: Tree) =
      ClassDef(Modifiers(), newTypeName("eval"), List(), Template(
        List(dslTrait("bakery.FailureCake")),
        emptyValDef,
        List(
          DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(),
            Block(List(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))),
          DefDef(Modifiers(), newTermName("main"), List(), List(List()), Ident(newTypeName("Any")), transformedBody))))

    def constructor = Apply(Select(New(Ident(newTypeName("eval"))), nme.CONSTRUCTOR), List())

    c.eval(c.Expr[Any](
      c.resetAllAttrs(Block(composeDSL(Literal(Constant(1))), constructor))))

    c.Expr[Any](Literal(Constant(1)))
  }
}
object Test extends App {
  bakery.Bakery.failure
}
11:08 ~/Projects/210x/sandbox (2.10.x)$ s
exception when typing implicit def liftAnyFails(evidence$1: reflect.Manifest): Object = bakery.FailureCake$class.liftAnyFails(__wrapper$1$3b9afa84dd664f0ba5c8b75c90de8b24$eval$1.this, evidence$1)

     while compiling: <no file>
        during phase: mixin
     library version: version 2.10.2-20130301-114301-5d54cf9e37
    compiler version: version 2.10.2-20130301-114301-5d54cf9e37
  reconstructed args:

  last tree to typer: TypeTree(trait FailureCake)
              symbol: trait FailureCake in package bakery (flags: <interface> abstract <trait> <lateinterface>)
   symbol definition: abstract trait FailureCake extends Object
                 tpe: bakery.FailureCake
       symbol owners: trait FailureCake -> package bakery
      context owners: method liftAnyFails -> class __wrapper$1$3b9afa84dd664f0ba5c8b75c90de8b24$eval$1 -> package __wrapper$1$3b9afa84dd664f0ba5c8b75c90de8b24

== Enclosing template or block ==

Apply( // implicit def liftAnyFails(evidence$1: reflect.Manifest): Object in object FailureCake$class, tree.tpe=Object
  "bakery"."FailureCake$class"."liftAnyFails" // implicit def liftAnyFails(evidence$1: reflect.Manifest): Object in object FailureCake$class, tree.tpe=(x$1: bakery.FailureCake, evidence$1: reflect.Manifest)Object
  // 2 arguments
  This("__wrapper$1$3b9afa84dd664f0ba5c8b75c90de8b24$eval$1")class __wrapper$1$3b9afa84dd664f0ba5c8b75c90de8b24$eval$1 extends FailureCake in package __wrapper$1$3b9afa84dd664f0ba5c8b75c90de8b24, tree.tpe=__wrapper$1$3b9afa84dd664f0ba5c8b75c90de8b24.__wrapper$1$3b9afa84dd664f0ba5c8b75c90de8b24$eval$1
  "evidence$1" // evidence$1: reflect.Manifest, tree.tpe=reflect.Manifest
)

== Expanded type of tree ==

TypeRef(TypeSymbol(abstract trait FailureCake extends Object))

unhandled exception while transforming <no source file>
error: exception during macro expansion:
scala.reflect.internal.FatalError: package scala does not have a member languageFeature$implicitConversions
	at scala.reflect.internal.Definitions$DefinitionsClass.scala$reflect$internal$Definitions$DefinitionsClass$$fatalMissingSymbol(Definitions.scala:1028)
	at scala.reflect.internal.Definitions$DefinitionsClass$$anonfun$getMember$1.apply(Definitions.scala:1052)
	at scala.reflect.internal.Definitions$DefinitionsClass$$anonfun$getMember$1.apply(Definitions.scala:1047)
	at scala.reflect.internal.Symbols$Symbol.orElse(Symbols.scala:2220)
	at scala.reflect.internal.Definitions$DefinitionsClass.getMember(Definitions.scala:1046)
	at scala.reflect.internal.Definitions$DefinitionsClass$$anonfun$getMember$1.apply(Definitions.scala:1050)
	at scala.reflect.internal.Definitions$DefinitionsClass$$anonfun$getMember$1.apply(Definitions.scala:1047)
	at scala.reflect.internal.Symbols$Symbol.orElse(Symbols.scala:2220)
	at scala.reflect.internal.Definitions$DefinitionsClass.getMember(Definitions.scala:1046)
	at scala.reflect.internal.Definitions$DefinitionsClass.getLanguageFeature(Definitions.scala:1031)
	at scala.reflect.internal.Definitions$DefinitionsClass.ImplicitConversionsFeature$lzycompute(Definitions.scala:1000)
	at scala.reflect.internal.Definitions$DefinitionsClass.ImplicitConversionsFeature(Definitions.scala:1000)
	at scala.tools.nsc.typechecker.Typers$Typer.typedDefDef(Typers.scala:2276)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5550)
	at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:839)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5623)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5680)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPos(Typers.scala:5685)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.scala$tools$nsc$transform$Mixin$MixinTransformer$$typedPos(Mixin.scala:483)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.attributedDef$1(Mixin.scala:653)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.scala$tools$nsc$transform$Mixin$MixinTransformer$$addDef$1(Mixin.scala:664)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.scala$tools$nsc$transform$Mixin$MixinTransformer$$addDefDef$1(Mixin.scala:672)
	at scala.tools.nsc.transform.Mixin$MixinTransformer$$anonfun$addNewDefs$2.apply(Mixin.scala:1093)
	at scala.tools.nsc.transform.Mixin$MixinTransformer$$anonfun$addNewDefs$2.apply(Mixin.scala:1040)
	at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
	at scala.collection.immutable.List.foreach(List.scala:318)
	at scala.reflect.internal.Scopes$Scope.foreach(Scopes.scala:315)
	at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.addNewDefs(Mixin.scala:1040)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.scala$tools$nsc$transform$Mixin$MixinTransformer$$postTransform(Mixin.scala:1147)
	at scala.tools.nsc.transform.Mixin$MixinTransformer$$anonfun$transform$1.apply(Mixin.scala:1261)
	at scala.tools.nsc.transform.Mixin$MixinTransformer$$anonfun$transform$1.apply(Mixin.scala:1261)
	at scala.reflect.internal.SymbolTable.atPhase(SymbolTable.scala:207)
	at scala.reflect.internal.SymbolTable.afterPhase(SymbolTable.scala:216)
	at scala.tools.nsc.Global.afterMixin(Global.scala:1103)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1261)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:471)
	at scala.reflect.api.Trees$Transformer.transformTemplate(Trees.scala:2904)
	at scala.reflect.internal.Trees$$anonfun$itransform$4.apply(Trees.scala:1280)
	at scala.reflect.internal.Trees$$anonfun$itransform$4.apply(Trees.scala:1279)
	at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:2936)
	at scala.reflect.internal.Trees$class.itransform(Trees.scala:1278)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:13)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:13)
	at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2897)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1258)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:471)
	at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:2927)
	at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:2925)
	at scala.collection.immutable.List.loop$1(List.scala:170)
	at scala.collection.immutable.List.mapConserve(List.scala:186)
	at scala.reflect.api.Trees$Transformer.transformStats(Trees.scala:2925)
	at scala.reflect.internal.Trees$$anonfun$itransform$7.apply(Trees.scala:1298)
	at scala.reflect.internal.Trees$$anonfun$itransform$7.apply(Trees.scala:1298)
	at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:2936)
	at scala.reflect.internal.Trees$class.itransform(Trees.scala:1297)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:13)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:13)
	at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2897)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1258)
	at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:471)
	at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:227)
	at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:464)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:431)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:431)
	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:431)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1583)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1557)
	at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.compile(ToolBoxFactory.scala:251)
	at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:416)
	at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.eval(ToolBoxFactory.scala:419)
	at scala.reflect.macros.runtime.Evals$class.eval(Evals.scala:16)
	at scala.reflect.macros.runtime.Context.eval(Context.scala:6)
	at bakery.Bakery$.failureImpl(Macros.scala:43)

one error found
@scabug
Copy link
Author

@scabug scabug commented Mar 11, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7240?orig=1
Reporter: @xeno-by
Affected Versions: 2.10.0

@scabug
Copy link
Author

@scabug scabug commented Mar 11, 2013

@scabug scabug closed this Mar 13, 2013
@scabug scabug added the has PR label Apr 7, 2017
@scabug scabug added this to the 2.10.2-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants