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

Type inference does not work on methods using dependent types and parameters with default value

    Details

      Description

      Here is a minimal test case that shows the problem:

      trait Main {
      
        trait A {
          type B
        }
      
        trait C {
          def c(a: A, x: Int = 0)(b: a.B)
        }
      
        def c: C
      
        def ok(a: A)(b: a.B) = c.c(a, 42)(b)
      
        def fail(a: A)(b: a.B) = c.c(a)(b)
      
      }
      

      If I remove the `x` parameter default value, or explicitly fill its value, it works fine.
      But compiling the above code produces the following error:

      [error] /Volumes/Home/workspace/scala-dependent-types/src/main/scala/Main.scala:15: type mismatch;
      [error]  found   : b.type (with underlying type a.B)
      [error]  required: x$1.B
      [error]   def fail(a: A)(b: a.B) = c.c(a)(b)
      

        Issue Links

          Activity

          Hide
          Julien Richard-Foy added a comment - - edited

          Note that if the `c` method is a top-level method rather than a method of the trait `C`, it compiles fine:

          trait Main {
          
            trait A {
              type B
            }
          
            def c(a: A, x: Int = 0)(b: a.B)
          
            def ok(a: A)(b: a.B) = c(a, 42)(b)
          
            def ok2(a: A)(b: a.B) = c(a)(b)
          
          }
          
          Show
          Julien Richard-Foy added a comment - - edited Note that if the `c` method is a top-level method rather than a method of the trait `C`, it compiles fine: trait Main { trait A { type B } def c(a: A, x: Int = 0)(b: a.B) def ok(a: A)(b: a.B) = c(a, 42)(b) def ok2(a: A)(b: a.B) = c(a)(b) }
          Hide
          Jason Zaugg added a comment -

          Thanks for the clear bug report.

          Working on a fix: https://github.com/retronym/scala/compare/ticket/7234

          Still a few subtle interactions to deal with.

          Here's a related crasher:

          trait Main {
            trait A {
              type B
            }
            trait C {
              def c(a: A, x: Int = 0)(bs: a.B*)
              def d(a: A, x: Int = 0)(b: a.B)
            }
            def c: C
            def fail3(a: A)(b: a.B) = c.c(a)(Seq[A#B](b): _*) // should fail, crashes with .setInfo(null)
          }
          
          Show
          Jason Zaugg added a comment - Thanks for the clear bug report. Working on a fix: https://github.com/retronym/scala/compare/ticket/7234 Still a few subtle interactions to deal with. Here's a related crasher: trait Main { trait A { type B } trait C { def c(a: A, x: Int = 0)(bs: a.B*) def d(a: A, x: Int = 0)(b: a.B) } def c: C def fail3(a: A)(b: a.B) = c.c(a)(Seq[A#B](b): _*) // should fail, crashes with .setInfo(null) }
          Hide
          Jason Zaugg added a comment - - edited

          I've opened another ticket for that crasher, SI-7238.

          Show
          Jason Zaugg added a comment - - edited I've opened another ticket for that crasher, SI-7238 .
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/2225/files
          Hide
          Julien Richard-Foy added a comment -

          Great, thanks for your reactivity.

          Show
          Julien Richard-Foy added a comment - Great, thanks for your reactivity.
          Hide
          Jason Zaugg added a comment -

          Unfortunately we had to revert this due to SI-7516.

          Right now, I don't see a straight forward way to deliver this fix without breaking that again.

          Show
          Jason Zaugg added a comment - Unfortunately we had to revert this due to SI-7516 . Right now, I don't see a straight forward way to deliver this fix without breaking that again.
          Hide
          Grzegorz Kossakowski added a comment -

          Unassigning and rescheduling to M7 as previous deadline was missed.

          Show
          Grzegorz Kossakowski added a comment - Unassigning and rescheduling to M7 as previous deadline was missed.

            People

            • Assignee:
              Unassigned
              Reporter:
              Julien Richard-Foy
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Development