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

Specialization + Upper Lower Bounds cause TypeError

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-M2, Scala 2.10.0
    • Fix Version/s: Scala 2.10.0-M3
    • Environment:

      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.tm

      Description

      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.

        Activity

        Hide
        Philipp Haller added a comment -

        Submitted pull request which adds test in pending/pos.

        Show
        Philipp Haller added a comment - Submitted pull request which adds test in pending/pos.
        Hide
        Aleksandar Prokopec added a comment -

        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.

        Show
        Aleksandar Prokopec added a comment - 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.

          People

          • Assignee:
            Aleksandar Prokopec
            Reporter:
            Josh Suereth
          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development