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

unspecialized variant called for overloaded specialized methods #9819

Open
scabug opened this issue Jun 15, 2016 · 1 comment
Open

unspecialized variant called for overloaded specialized methods #9819

scabug opened this issue Jun 15, 2016 · 1 comment

Comments

@scabug
Copy link

scabug commented Jun 15, 2016

Specialized methods called with an explicit (specialized) type argument invokes a generic erased variant instead of the specialized one when the method is overloaded

	class Spec[@specialized(Int) A](as :Seq[A]) {
		def head :A = as.head
	}




	object Specialized {
		def apply[@specialized(Int) A](as :A*) :Spec[A] = new Spec(as)

		//second apply method (unused in this example)
		def apply[@specialized(Int) A](spec :Spec[A]) :A = spec.head

		def wrap[@specialized(Int) A](as :Seq[A]) :Spec[A] = new Spec(as)

		//second wrap method (unused in this example)
		def wrap[@specialized(Int) A](spec :Spec[A]) :A = spec.head
	}


	val notSpecialized = Specialized[Int]()
	val specialized = Specialized(Seq[Int]():_*) //works
	val specializedToo :Spec[Int] = Specialized() //works

	val notSpecializedEither = Specialized.wrap[Int](Seq())
	val okSpecialized = Specialized.wrap(Seq[Int]())

	def show(a :AnyRef) = println(a.getClass.getName) 

	Seq(notSpecialized, specialized, specializedToo, notSpecializedEither, okSpecialized).foreach(show)

notSpecialized and notSpecializedEither return generic erased versions of Spec instead of the Int specialization.

@scabug
Copy link
Author

scabug commented Jun 15, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9819?orig=1
Reporter: Marcin Mościcki (mmoscicki)
Affected Versions: 2.11.8

@scabug scabug added this to the Backlog milestone Apr 7, 2017
plokhotnyuk added a commit to plokhotnyuk/jsoniter-scala that referenced this issue Nov 3, 2019
…write methods to mitigate non-fixed Scala bugs keeping source compatibility: scala/bug#10754 and scala/bug#9819
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants