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

Spurious type error when object defined and returned from a block

    Details

      Description

      In 2.7.1 final

      { object Bar ; Bar }
      

      causes type error

      <console>:4: error: type mismatch;
       found   : Bar.type(in object $$iw) where type Bar.type(in object $$iw) <: Bar with Singleton
       required: Bar.type(in value res0) forSome { type Bar.type(in value res0) <: Bar(in value res0) with Singleton; type Bar(in value res0) <: java.lang.Object with ScalaObject }
             val res0 = 
      

      Whereas the somewhat similar code

      {class Bar; new Bar()}
      

      results in

      res1: java.lang.Object with ScalaObject = Bar$$1@6f9f88
      

      The first example should probably result in a ScalaObject with Singleton or similar. And, in fact, explicitly typing the block solves the problem

      {object Bar; Bar}:ScalaObject with Singleton
      res2: ScalaObject with Singleton = Bar$$2$$@189b9bd
      

        Issue Links

          Activity

          Hide
          James Iry added a comment -

          This may be related to SI-1195

          Show
          James Iry added a comment - This may be related to SI-1195
          Hide
          James Iry added a comment -

          ScalaObject might be all that should be inferred. That's what this code unifies to:

          > object Bar
          > object Foo
          > var x = 1
          > val foo = if (x == 1) Foo else Bar

          foo: ScalaObject = Foo$$@103c520

          Show
          James Iry added a comment - ScalaObject might be all that should be inferred. That's what this code unifies to: > object Bar > object Foo > var x = 1 > val foo = if (x == 1) Foo else Bar foo: ScalaObject = Foo$$@103c520
          Hide
          Seth Tisue added a comment -

          any chance of this bug getting some attention? there are a lot of ways to trigger this: see also SI-1195, SI-4171, plus this one (very similar to SI-4171) I found today:

          scala> { class A; class B extends A; classOf[B] }
          <console>:7: error: type mismatch;
           found   : java.lang.Class[B(in value res4)] where type B(in value res4) <: A with ScalaObject
           required: java.lang.Class[_ <: A with ScalaObject]
                 val res4 =
                     ^
          
          Show
          Seth Tisue added a comment - any chance of this bug getting some attention? there are a lot of ways to trigger this: see also SI-1195 , SI-4171 , plus this one (very similar to SI-4171 ) I found today: scala> { class A; class B extends A; classOf[B] } <console>:7: error: type mismatch; found : java.lang.Class[B(in value res4)] where type B(in value res4) <: A with ScalaObject required: java.lang.Class[_ <: A with ScalaObject] val res4 = ^
          Hide
          Paul Phillips added a comment -

          Fixed in 7a6fa80937 or 7a6fa80937^ .

          Show
          Paul Phillips added a comment - Fixed in 7a6fa80937 or 7a6fa80937^ .

            People

            • Assignee:
              Paul Phillips
              Reporter:
              James Iry
              TracCC:
              Paul Phillips, Seth Tisue
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development