Scala Programming Language
  1. Scala Programming Language
  2. SI-7980

Quasiquotes fail on splicee with generic type

    Details

      Description

      scala> def Name[T:TypeTag](name:String): T = implicitly[TypeTag[T]] match {
           |    case t => newTypeName(name).asInstanceOf[T]
           |  }
      warning: there were 1 deprecation warning(s); re-run with -deprecation for details
      Name: [T](name: String)(implicit evidence$1: reflect.runtime.universe.TypeTag[T])T
      
      scala> val X = "ASDF"
      X: String = ASDF
      
      scala> println(q"class ${Name(X)}{  }")
      <console>:32: error: exception during macro expansion:
      java.util.NoSuchElementException: head of empty list
      	at scala.collection.immutable.Nil$.head(List.scala:337)
      	at scala.collection.immutable.Nil$.head(List.scala:334)
      	at scala.tools.reflect.quasiquotes.Holes$class.parseCardinality(Holes.scala:183)
      	at scala.tools.reflect.quasiquotes.Quasiquotes.parseCardinality(Quasiquotes.scala:6)
      	at scala.tools.reflect.quasiquotes.Holes$Hole$.apply(Holes.scala:158)
      	at scala.tools.reflect.quasiquotes.Placeholders$class.appendHole$1(Placeholders.scala:36)
      	at scala.tools.reflect.quasiquotes.Placeholders$$anonfun$code$1.apply(Placeholders.scala:48)
      	at scala.tools.reflect.quasiquotes.Placeholders$$anonfun$code$1.apply(Placeholders.scala:45)
      	at scala.reflect.internal.util.Collections$class.foreach2(Collections.scala:190)
      	at scala.reflect.internal.SymbolTable.foreach2(SymbolTable.scala:14)
      	at scala.tools.reflect.quasiquotes.Placeholders$class.code(Placeholders.scala:45)
      	at scala.tools.reflect.quasiquotes.Quasiquotes.code$lzycompute(Quasiquotes.scala:6)
      	at scala.tools.reflect.quasiquotes.Quasiquotes.code(Quasiquotes.scala:6)
      	at scala.tools.reflect.quasiquotes.Quasiquotes.expandQuasiquote(Quasiquotes.scala:47)
      	at scala.tools.reflect.FastTrack$$anonfun$1$$anonfun$apply$7$$anonfun$applyOrElse$7.apply(FastTrack.scala:51)
      	at scala.tools.reflect.FastTrack$$anonfun$1$$anonfun$apply$7$$anonfun$applyOrElse$7.apply(FastTrack.scala:51)
      	at scala.tools.reflect.FastTrack$FastTrackEntry.apply(FastTrack.scala:35)
      	at scala.tools.reflect.FastTrack$FastTrackEntry.apply(FastTrack.scala:30)
      	at scala.tools.nsc.typechecker.Macros$class.scala$tools$nsc$typechecker$Macros$$macroExpandWithRuntime(Macros.scala:735)
      
                     println(q"class ${Name(X)}{  }")
      

        Activity

        Hide
        Denys Shabalin added a comment -

        Failure seem to happen when type which is iterable doesn't have any type arguments. Need to handle that differently in parseCardinality.

        Show
        Denys Shabalin added a comment - Failure seem to happen when type which is iterable doesn't have any type arguments. Need to handle that differently in parseCardinality.
        Hide
        Denys Shabalin added a comment -

        The real problem here was inference of Nothing as return type of the Name function and quasiquotes' inability to handle that type. The bug in parseCardinality wasn't the real cause of failure here. Both of them are fixed now in my wip branch.

        Show
        Denys Shabalin added a comment - The real problem here was inference of Nothing as return type of the Name function and quasiquotes' inability to handle that type. The bug in parseCardinality wasn't the real cause of failure here. Both of them are fixed now in my wip branch.
        Hide
        Denys Shabalin added a comment -
        Show
        Denys Shabalin added a comment - Fixed in https://github.com/scala/scala/pull/3255

          People

          • Assignee:
            Denys Shabalin
            Reporter:
            Denys Shabalin
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development