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

Implicit lookup failure in method local types

    Details

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

      2.9.1

      Description

      Implicit lookup fails in method local types.

      class LocalImplicitTezt {
      
          trait Foo[x]
      
          class TestOk {
              trait My
              object My {
                  implicit def Foo[My]: Foo[My] = new Foo[My] {}
              }
      
              implicitly[Foo[My]]
          }
      
          def testNo {
              trait My
              object My {
                  implicit def Foo[My]: Foo[My] = new Foo[My] {}
              }
      
              implicitly[Foo[My]] // could not find implicit value for parameter e: LocalImplicitTezt.this.Foo[My]
          }
      
      }
      

        Activity

        Hide
        Paul Phillips added a comment -

        That's a little perverse. It does work if you skip the companion object.

        trait My
        implicit def Foo[My]: Foo[My] = new Foo[My] {}
        
        Show
        Paul Phillips added a comment - That's a little perverse. It does work if you skip the companion object. trait My implicit def Foo[My]: Foo[My] = new Foo[My] {}
        Hide
        Miles Sabin added a comment -

        I've just tripped over something that looks very similar,

        object ImplicitScope {
          class A[T]
          object B {
            implicit def ab = new A[B.type]
          }
          
          implicitly[A[B.type]]     // OK
          
          def foo {
            object B2 {
              implicit def ab = new A[B2.type]
            }
            
            implicitly[A[B2.type]]  // Error
          }
        }
        

        With the latest trunk I see,

        miles@lewis:SI-4975$ scalac-trunk src/implicitscope.scala
        src/implicitscope.scala:14: error: could not find implicit value for parameter e: ImplicitScope.A[B2.type]
            implicitly[A[B2.type]]
                      ^
        one error found
        miles@lewis:SI-4975$ scalac-trunk -version
        Scala compiler version 2.10.0.r26094-b20111201020254 -- Copyright 2002-2011, LAMP/EPFL
        
        Show
        Miles Sabin added a comment - I've just tripped over something that looks very similar, object ImplicitScope { class A[T] object B { implicit def ab = new A[B.type] } implicitly[A[B.type]] // OK def foo { object B2 { implicit def ab = new A[B2.type] } implicitly[A[B2.type]] // Error } } With the latest trunk I see, miles@lewis:SI-4975$ scalac-trunk src/implicitscope.scala src/implicitscope.scala:14: error: could not find implicit value for parameter e: ImplicitScope.A[B2.type] implicitly[A[B2.type]] ^ one error found miles@lewis:SI-4975$ scalac-trunk -version Scala compiler version 2.10.0.r26094-b20111201020254 -- Copyright 2002-2011, LAMP/EPFL
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/592

          People

          • Assignee:
            Martin Odersky
            Reporter:
            Shunsuke Sogame
          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development