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

Specialization + Upper Lower Bounds cause TypeError #5564

Closed
scabug opened this issue Mar 11, 2012 · 3 comments
Closed

Specialization + Upper Lower Bounds cause TypeError #5564

scabug opened this issue Mar 11, 2012 · 3 comments

Comments

@scabug
Copy link

scabug commented Mar 11, 2012

The following mixture of attempting a phantom-type constraint + specialization explodes at compile time:

trait C
class Foo[@specialized(Int) T, A] {
  def bar[B >: A <: C]: T = ???
}

With the following exception:

error: 
     while compiling:  /home/jsuereth/projects/tmp/phantom-bug.scala
       current phase:  specialize
     library version:  version 2.10.0-M2-0118-gf1c39dd981-2012-03-11
    compiler version:  version 2.10.0-M2-0118-gf1c39dd981-2012-03-11
  reconstructed args:  -Xscript Main -d /tmp/scalascript5606505759334571591.tmp

uncaught exception during compilation: scala.reflect.internal.Types$TypeError

Remove any one of the type bounds makes the code succeed. Removing the @Specialize annotation also makes the code succeed.

@scabug
Copy link
Author

scabug commented Mar 11, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5564?orig=1
Reporter: @jsuereth
Affected Versions: 2.10.0-M2, 2.10.0

@scabug
Copy link
Author

scabug commented May 8, 2012

@phaller said:
Submitted pull request which adds test in pending/pos.

@scabug
Copy link
Author

scabug commented May 8, 2012

@axel22 said:
More generally, you're not allowed to do a call such as this one:

class Foo[/*@specialized(Int) */T, A] {
  def bar[B >: A <: AnyRef]: T = throw new Exception
  
  bar[A]
}

since it's possible that A is not a subtype of AnyRef at all in certain contexts. So, generating a bridge bar$mcI$sp for bar will contain an expression which is not type-safe. Meaning that instead of the compiler failing, an error should be reported here.

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