Skip to content

"No TypeTag available" for type member regression #9865

@scabug

Description

@scabug

This example compiles using Scala 2.10.4 but not with 2.11.7

import scala.reflect.runtime.universe._

trait Parser {
  type Result
  def parse(s: String): Result
}

object Parser {

  type TP[A] = Parser { type Result = A }

  def apply[A](fn: String => A): Parser { type Result = A } =
    new Parser {
      override type Result = A
      override def parse(s: String): Result = fn(s)
    }

  def register[A : TypeTag](parser: Parser.TP[A]): Unit = {
    // do registration ...
  }

  register(Parser(_.toInt))
}
[ERROR] Parser.scala:24: error: No TypeTag available for this.Result
[ERROR]   register(Parser(_.toInt))
[ERROR]           ^

An easy workaround it to just change the change the type of apply:

def apply[A](fn: String => A): Parser.TP[A] = ...

Another workaround is to specify the type parameter when calling register:

register[Int](Parser(_.toInt))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions