miniboxing-plugin icon indicating copy to clipboard operation
miniboxing-plugin copied to clipboard

@specialized code reports type mismatch in the presence of miniboxing but succeeds with -P:minibox:mark-all

Open biboudis opened this issue 9 years ago • 1 comments

The following snippet reproduces the errors I got:

import scala.reflect.ClassTag

class Stream[@specialized(Long) T: ClassTag](val loop : (T => Boolean) => Boolean) {
  def map [@specialized(Long) R : ClassTag] (f: T => R) : Stream[R] = {
    new Stream(k => loop(value => k(f(value))))
  }
}

object Stream {
  @inline def apply[@specialized(Long) T: ClassTag](xs: Array[T]) = ???
}

and the sbt file:

version := "1.0"

scalaVersion := "2.11.6"

resolvers ++= Seq(Resolver.sonatypeRepo("releases"), Resolver.sonatypeRepo("snapshots"))

libraryDependencies ++= Seq(
  "org.scala-lang" % "scala-reflect" % "2.11.4",
  "org.scala-miniboxing.plugins" %% "miniboxing-runtime" % "0.4-M4"
)

ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }

addCompilerPlugin("org.scala-miniboxing.plugins" %% "miniboxing-plugin" % "0.4-M4")
// scalacOptions ++= Seq("-P:minibox:mark-all")

Leaving the last line commented out, I get:

> compile
[info] Compiling 1 Scala source to /home/bibou/Projects/test-functions-miniboxing-specialized/target/scala-2.11/classes...
[error] /home/bibou/Projects/test-functions-miniboxing-specialized/src/main/scala/Stream.scala:5: type mismatch;
[error]  found   : T
[error]  required: Long => Boolean
[error]     new Stream(k => loop(value => k(f(value))))
[error]                                   ^
[error] one error found
[error] (compile:compile) Compilation failed

biboudis avatar Jun 07 '15 23:06 biboudis

Thanks @biboudis! I can reproduce it locally:

$ cat gh-bug-235.scala 
import scala.reflect.ClassTag

class Stream[@specialized(Long) T: ClassTag](val loop : (T => Boolean) => Boolean) {
  def map [@specialized(Long) R : ClassTag] (f: T => R) : Stream[R] = {
    new Stream(k => loop(value => k(f(value))))
  }
}

object Stream {
  @inline def apply[@specialized(Long) T: ClassTag](xs: Array[T]) = ???
}

$ mb-scalac gh-bug-235.scala 
gh-bug-235.scala:5: error: type mismatch;
 found   : T
 required: Long => Boolean
    new Stream(k => loop(value => k(f(value))))
                                  ^
one error found

VladUreche avatar Jun 07 '15 23:06 VladUreche