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

Unhelpful compiler error message with incompatible structural types

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
    • Environment:

      Scala version 2.10.0.r25445-b20110805020350 (OpenJDK 64-Bit Server VM, Java 1.6.0_22).

      Description

      scala> def foo: AnyRef{def bar: String} =  new AnyRef{def bar = 42}
      <console>:7: error: type mismatch;
       found   : java.lang.Object{}
       required: AnyRef{def bar: String}
             def foo: AnyRef{def bar: String} =  new AnyRef{def bar = 42}
                                                 ^
      

      It looks a bit like as if the compiler error message would use the erasure of the right expression return type. I would have expected something like:

      scala> def foo: AnyRef{def bar: String} =  new AnyRef{def bar = 42}
      <console>:7: error: type mismatch;
       found   : AnyRef{def bar: Int}
       required: AnyRef{def bar: String}
             def foo: AnyRef{def bar: String} =  new AnyRef{def bar = 42}
                                                                      ^
      

      The caret positioning could also be a bit better if it pointed to the def bar.

        Issue Links

          Activity

          Hide
          Commit Message Bot added a comment -

          (extempore in r25456) Improved structural type error messages, and other error message
          related boosts. Closes SI-4877, review by odersky.

          Show
          Commit Message Bot added a comment - (extempore in r25456 ) Improved structural type error messages, and other error message related boosts. Closes SI-4877 , review by odersky.

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Simon Ochsenreither
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development