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

Ambiguous type printing gives rise to confusing type errors

    Details

      Description

      Scala's compiler prints several types ambiguously.

      For example:

      • functions that takes n arguments of type A, B, C, .. and functions that take a single n-tuple (A, B, C, ...) argument.
      • higher-order functions (A => B) => C and curried functions A => B => C.

      This can produce some confusing type errors such as

      scala> k(z)
      <console>:10: error: type mismatch;
       found : Int => Int => Int
       required: Int => Int => Int

      Or

      scala> h(g)
      <console>:10: error: type mismatch;
       found : (Int, Int) => Int
       required: (Int, Int) => Int

      Here's a gist of how to set up these particular type errors: https://gist.github.com/1655807

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          Please search for existing tickets before opening new ones. Already fixed in trunk. However all is not lost, I used this ticket as motivation to backport those two commits for 2.9.2.

          scala> def k( j : (Int => Int) => Int ) : Int = j(_+1)
          k: (j: (Int => Int) => Int)Int
          
          scala> def p(q : Int => Int) : Int = q(0)
          p: (q: Int => Int)Int
          
          scala> def z = (x : Int) => (y : Int) => x + y
          z: Int => (Int => Int)
          
          scala> k(p)
          res0: Int = 1
          
          scala> k(z)
          <console>:10: error: type mismatch;
           found   : Int => (Int => Int)
           required: (Int => Int) => Int
                        k(z)
                          ^
          
          Show
          Paul Phillips added a comment - Please search for existing tickets before opening new ones. Already fixed in trunk. However all is not lost, I used this ticket as motivation to backport those two commits for 2.9.2. scala> def k( j : (Int => Int) => Int ) : Int = j(_+1) k: (j: (Int => Int) => Int)Int scala> def p(q : Int => Int) : Int = q(0) p: (q: Int => Int)Int scala> def z = (x : Int) => (y : Int) => x + y z: Int => (Int => Int) scala> k(p) res0: Int = 1 scala> k(z) <console>:10: error: type mismatch; found : Int => (Int => Int) required: (Int => Int) => Int k(z) ^
          Hide
          Paul Phillips added a comment -

          Oh, and

          scala> h(g)
          <console>:11: error: type mismatch;
           found   : ((Int, Int)) => Int
           required: (Int, Int) => Int
                        h(g)
                          ^
          
          Show
          Paul Phillips added a comment - Oh, and scala> h(g) <console>:11: error: type mismatch; found : ((Int, Int)) => Int required: (Int, Int) => Int h(g) ^
          Hide
          Noah Luck Easterly added a comment -

          Awesome, thanks. Sorry I didn't notice this was already fixed in trunk. I'll be sure to spread the word.

          Show
          Noah Luck Easterly added a comment - Awesome, thanks. Sorry I didn't notice this was already fixed in trunk. I'll be sure to spread the word.

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Noah Luck Easterly
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development