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

type constructor inference works for method call but fails for constructor invocation

    Details

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

      tcpoly infer

      Description

      = problem =

      Type Constructor inference doesn't behave consistently across method calls and constructor invocations.

      trait M[V[_]]
      
      class Cls[V[_]](c: M[V])
      
      object Cls{
        def apply[V[_]](c: M[V]): Cls[V] = new Cls[V](c)
      }
      
      object test {
        val c: M[Option] = new M[Option] {}
        new Cls(c)         // does not infer.
        new Cls[Option](c) // okay
        Cls(c)             // okay
      }
      

      Tested with Scala 2.8.1

        Activity

        Hide
        Sciss added a comment -

        this gets really nasty also with method invocations which do perfect inference until you introduce higher-kinded type arguments.

        in the attached file you can see that for the first-order case this works:

        def test( implicit sys: KSys, c: KCtx ) {
           val p = Factory.test( "Test" )
        }
        

        in the second-order case, the implicits are not found. if i add them explicitly, the compiler complains:

        <console>:38: error: no type parameters for method test: (implicit sys: Sys[A,B],implicit c: A)Proc[A,B] exist so that it can be applied to arguments (KSys, KCtx)
         --- because ---
        argument expression's type is not compatible with formal parameter type;
         found   : KSys
         required: Sys[?A,?B]
                  val p = Factory.test( "Test" )( sys, c )
                                      ^
        

        so i need to annotate all types. this is a real show stopper for a larger generified library.

        Show
        Sciss added a comment - this gets really nasty also with method invocations which do perfect inference until you introduce higher-kinded type arguments. in the attached file you can see that for the first-order case this works: def test( implicit sys: KSys, c: KCtx ) { val p = Factory.test( "Test" ) } in the second-order case, the implicits are not found. if i add them explicitly, the compiler complains: <console>:38: error: no type parameters for method test: (implicit sys: Sys[A,B],implicit c: A)Proc[A,B] exist so that it can be applied to arguments (KSys, KCtx) --- because --- argument expression's type is not compatible with formal parameter type; found : KSys required: Sys[?A,?B] val p = Factory.test( "Test" )( sys, c ) ^ so i need to annotate all types. this is a real show stopper for a larger generified library.
        Hide
        Sciss added a comment -

        Example where method calls must be annotated

        Show
        Sciss added a comment - Example where method calls must be annotated
        Hide
        Jason Zaugg added a comment -

        See more examples in SI-4347

        Show
        Jason Zaugg added a comment - See more examples in SI-4347
        Hide
        Paul Phillips added a comment -

        Fixed in r25110.

        Show
        Paul Phillips added a comment - Fixed in r25110.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Jason Zaugg
            TracCC:
            Mikhail Vorozhtsov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development