Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

By-name argument in PartialFunction says "key not found: method $anonfun" #10389

Closed
Jasper-M opened this issue Nov 19, 2020 · 2 comments · Fixed by #12847
Closed

By-name argument in PartialFunction says "key not found: method $anonfun" #10389

Jasper-M opened this issue Nov 19, 2020 · 2 comments · Fixed by #12847

Comments

@Jasper-M
Copy link
Contributor

Minimized code

import scala.util._

object FooBar {
  def foo = List("1","two","3").collect{ x => 
    Try(x.toInt) match { 
      case Success(int) => int 
    }
  }
}

Output (click arrow to expand)

java.util.NoSuchElementException: key not found: method $anonfun while traversing x
java.util.NoSuchElementException: key not found: method $anonfun while traversing augmentString(x)
java.util.NoSuchElementException: key not found: method $anonfun while traversing scala.collection.StringOps.toInt$extension(augmentString(x))
java.util.NoSuchElementException: key not found: method $anonfun while traversing scala.collection.StringOps.toInt$extension(augmentString(x)):Int
java.util.NoSuchElementException: key not found: method $anonfun while traversing def $anonfun(): Int = 
  scala.collection.StringOps.toInt$extension(augmentString(x)):Int
java.util.NoSuchElementException: key not found: method $anonfun while traversing {
  def $anonfun(): Int = 
    scala.collection.StringOps.toInt$extension(augmentString(x)):Int
  closure($anonfun:JFunction0$mcI$sp)
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing util.Try.apply(
  {
    def $anonfun(): Int = 
      scala.collection.StringOps.toInt$extension(augmentString(x)):Int
    closure($anonfun:JFunction0$mcI$sp)
  }
)
java.util.NoSuchElementException: key not found: method $anonfun while traversing util.Try.apply(
  {
    def $anonfun(): Int = 
      scala.collection.StringOps.toInt$extension(augmentString(x)):Int
    closure($anonfun:JFunction0$mcI$sp)
  }
):scala.util.Try
java.util.NoSuchElementException: key not found: method $anonfun while traversing case val x1: scala.util.Try = 
  util.Try.apply(
    {
      def $anonfun(): Int = 
        scala.collection.StringOps.toInt$extension(augmentString(x)):Int
      closure($anonfun:JFunction0$mcI$sp)
    }
  ):scala.util.Try
java.util.NoSuchElementException: key not found: method $anonfun while traversing {
  case val x1: scala.util.Try = 
    util.Try.apply(
      {
        def $anonfun(): Int = 
          scala.collection.StringOps.toInt$extension(augmentString(x)):Int
        closure($anonfun:JFunction0$mcI$sp)
      }
    ):scala.util.Try
  if x1.isInstanceOf[scala.util.Success] then 
    {
      case val int: Int = 
        scala.Int.unbox(x1.asInstanceOf[scala.util.Success].value())
      return[matchResult1] true
    }
   else ()
  return[matchResult1] false
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing matchResult1[Boolean]: 
  {
    case val x1: scala.util.Try = 
      util.Try.apply(
        {
          def $anonfun(): Int = 
            scala.collection.StringOps.toInt$extension(augmentString(x)):Int
          closure($anonfun:JFunction0$mcI$sp)
        }
      ):scala.util.Try
    if x1.isInstanceOf[scala.util.Success] then 
      {
        case val int: Int = 
          scala.Int.unbox(x1.asInstanceOf[scala.util.Success].value())
        return[matchResult1] true
      }
     else ()
    return[matchResult1] false
  }
java.util.NoSuchElementException: key not found: method $anonfun while traversing override final def isDefinedAt(x: String): Boolean = 
  matchResult1[Boolean]: 
    {
      case val x1: scala.util.Try = 
        util.Try.apply(
          {
            def $anonfun(): Int = 
              scala.collection.StringOps.toInt$extension(augmentString(x)):Int
            closure($anonfun:JFunction0$mcI$sp)
          }
        ):scala.util.Try
      if x1.isInstanceOf[scala.util.Success] then 
        {
          case val int: Int = 
            scala.Int.unbox(x1.asInstanceOf[scala.util.Success].value())
          return[matchResult1] true
        }
       else ()
      return[matchResult1] false
    }
java.util.NoSuchElementException: key not found: method $anonfun while traversing  extends scala.runtime.AbstractPartialFunction, java.io.Serializable {
  def <init>(): Unit = 
    {
      super()
      ()
    }
  override final def isDefinedAt(x: String): Boolean = 
    matchResult1[Boolean]: 
      {
        case val x1: scala.util.Try = 
          util.Try.apply(
            {
              def $anonfun(): Int = 
                scala.collection.StringOps.toInt$extension(augmentString(x)):Int
              closure($anonfun:JFunction0$mcI$sp)
            }
          ):scala.util.Try
        if x1.isInstanceOf[scala.util.Success] then 
          {
            case val int: Int = 
              scala.Int.unbox(x1.asInstanceOf[scala.util.Success].value())
            return[matchResult1] true
          }
         else ()
        return[matchResult1] false
      }
  override final def applyOrElse(x: String, default: Function1): Object = 
    matchResult2[Object]: 
      {
        case val x4: scala.util.Try = 
          util.Try.apply(
            {
              def $anonfun(): Int = 
                scala.collection.StringOps.toInt$extension(augmentString(x)):Int
              closure($anonfun:JFunction0$mcI$sp)
            }
          ):scala.util.Try
        if x4.isInstanceOf[scala.util.Success] then 
          {
            case val int: Int = 
              scala.Int.unbox(x4.asInstanceOf[scala.util.Success].value())
            return[matchResult2] 
              {
                scala.Int.box(int:Int)
              }
          }
         else ()
        return[matchResult2] default.apply(x)
      }
  override final def isDefinedAt(x: Object): Boolean = 
    this.isDefinedAt(x.asInstanceOf[String])
  override final def applyOrElse(x: Object, default: Function1): Object = 
    this.applyOrElse(x.asInstanceOf[String], default)
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing final class $anon extends scala.runtime.AbstractPartialFunction, 
  java.io.Serializable
 {
  def <init>(): Unit = 
    {
      super()
      ()
    }
  override final def isDefinedAt(x: String): Boolean = 
    matchResult1[Boolean]: 
      {
        case val x1: scala.util.Try = 
          util.Try.apply(
            {
              def $anonfun(): Int = 
                scala.collection.StringOps.toInt$extension(augmentString(x)):Int
              closure($anonfun:JFunction0$mcI$sp)
            }
          ):scala.util.Try
        if x1.isInstanceOf[scala.util.Success] then 
          {
            case val int: Int = 
              scala.Int.unbox(x1.asInstanceOf[scala.util.Success].value())
            return[matchResult1] true
          }
         else ()
        return[matchResult1] false
      }
  override final def applyOrElse(x: String, default: Function1): Object = 
    matchResult2[Object]: 
      {
        case val x4: scala.util.Try = 
          util.Try.apply(
            {
              def $anonfun(): Int = 
                scala.collection.StringOps.toInt$extension(augmentString(x)):Int
              closure($anonfun:JFunction0$mcI$sp)
            }
          ):scala.util.Try
        if x4.isInstanceOf[scala.util.Success] then 
          {
            case val int: Int = 
              scala.Int.unbox(x4.asInstanceOf[scala.util.Success].value())
            return[matchResult2] 
              {
                scala.Int.box(int:Int)
              }
          }
         else ()
        return[matchResult2] default.apply(x)
      }
  override final def isDefinedAt(x: Object): Boolean = 
    this.isDefinedAt(x.asInstanceOf[String])
  override final def applyOrElse(x: Object, default: Function1): Object = 
    this.applyOrElse(x.asInstanceOf[String], default)
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing {
  final class $anon extends scala.runtime.AbstractPartialFunction, 
    java.io.Serializable
   {
    def <init>(): Unit = 
      {
        super()
        ()
      }
    override final def isDefinedAt(x: String): Boolean = 
      matchResult1[Boolean]: 
        {
          case val x1: scala.util.Try = 
            util.Try.apply(
              {
                def $anonfun(): Int = 
                  scala.collection.StringOps.toInt$extension(augmentString(x)):
                    Int
                closure($anonfun:JFunction0$mcI$sp)
              }
            ):scala.util.Try
          if x1.isInstanceOf[scala.util.Success] then 
            {
              case val int: Int = 
                scala.Int.unbox(x1.asInstanceOf[scala.util.Success].value())
              return[matchResult1] true
            }
           else ()
          return[matchResult1] false
        }
    override final def applyOrElse(x: String, default: Function1): Object = 
      matchResult2[Object]: 
        {
          case val x4: scala.util.Try = 
            util.Try.apply(
              {
                def $anonfun(): Int = 
                  scala.collection.StringOps.toInt$extension(augmentString(x)):
                    Int
                closure($anonfun:JFunction0$mcI$sp)
              }
            ):scala.util.Try
          if x4.isInstanceOf[scala.util.Success] then 
            {
              case val int: Int = 
                scala.Int.unbox(x4.asInstanceOf[scala.util.Success].value())
              return[matchResult2] 
                {
                  scala.Int.box(int:Int)
                }
            }
           else ()
          return[matchResult2] default.apply(x)
        }
    override final def isDefinedAt(x: Object): Boolean = 
      this.isDefinedAt(x.asInstanceOf[String])
    override final def applyOrElse(x: Object, default: Function1): Object = 
      this.applyOrElse(x.asInstanceOf[String], default)
  }
  new scala.runtime.AbstractPartialFunction with java.io.Serializable {...}():
    scala.runtime.AbstractPartialFunction
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing {
  {
    final class $anon extends scala.runtime.AbstractPartialFunction, 
      java.io.Serializable
     {
      def <init>(): Unit = 
        {
          super()
          ()
        }
      override final def isDefinedAt(x: String): Boolean = 
        matchResult1[Boolean]: 
          {
            case val x1: scala.util.Try = 
              util.Try.apply(
                {
                  def $anonfun(): Int = 
                    scala.collection.StringOps.toInt$extension(augmentString(x))
                      :
                    Int
                  closure($anonfun:JFunction0$mcI$sp)
                }
              ):scala.util.Try
            if x1.isInstanceOf[scala.util.Success] then 
              {
                case val int: Int = 
                  scala.Int.unbox(x1.asInstanceOf[scala.util.Success].value())
                return[matchResult1] true
              }
             else ()
            return[matchResult1] false
          }
      override final def applyOrElse(x: String, default: Function1): Object = 
        matchResult2[Object]: 
          {
            case val x4: scala.util.Try = 
              util.Try.apply(
                {
                  def $anonfun(): Int = 
                    scala.collection.StringOps.toInt$extension(augmentString(x))
                      :
                    Int
                  closure($anonfun:JFunction0$mcI$sp)
                }
              ):scala.util.Try
            if x4.isInstanceOf[scala.util.Success] then 
              {
                case val int: Int = 
                  scala.Int.unbox(x4.asInstanceOf[scala.util.Success].value())
                return[matchResult2] 
                  {
                    scala.Int.box(int:Int)
                  }
              }
             else ()
            return[matchResult2] default.apply(x)
          }
      override final def isDefinedAt(x: Object): Boolean = 
        this.isDefinedAt(x.asInstanceOf[String])
      override final def applyOrElse(x: Object, default: Function1): Object = 
        this.applyOrElse(x.asInstanceOf[String], default)
    }
    new scala.runtime.AbstractPartialFunction with java.io.Serializable {...}():
      scala.runtime.AbstractPartialFunction
  }
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing List().apply(scala.runtime.ScalaRunTime.wrapRefArray(["1","two","3" : String])).
  asInstanceOf
[scala.collection.immutable.List].collect(
  {
    {
      final class $anon extends scala.runtime.AbstractPartialFunction, 
        java.io.Serializable
       {
        def <init>(): Unit = 
          {
            super()
            ()
          }
        override final def isDefinedAt(x: String): Boolean = 
          matchResult1[Boolean]: 
            {
              case val x1: scala.util.Try = 
                util.Try.apply(
                  {
                    def $anonfun(): Int = 
                      scala.collection.StringOps.toInt$extension(
                        augmentString(x)
                      ):Int
                    closure($anonfun:JFunction0$mcI$sp)
                  }
                ):scala.util.Try
              if x1.isInstanceOf[scala.util.Success] then 
                {
                  case val int: Int = 
                    scala.Int.unbox(x1.asInstanceOf[scala.util.Success].value())
                  return[matchResult1] true
                }
               else ()
              return[matchResult1] false
            }
        override final def applyOrElse(x: String, default: Function1): Object = 
          matchResult2[Object]: 
            {
              case val x4: scala.util.Try = 
                util.Try.apply(
                  {
                    def $anonfun(): Int = 
                      scala.collection.StringOps.toInt$extension(
                        augmentString(x)
                      ):Int
                    closure($anonfun:JFunction0$mcI$sp)
                  }
                ):scala.util.Try
              if x4.isInstanceOf[scala.util.Success] then 
                {
                  case val int: Int = 
                    scala.Int.unbox(x4.asInstanceOf[scala.util.Success].value())
                  return[matchResult2] 
                    {
                      scala.Int.box(int:Int)
                    }
                }
               else ()
              return[matchResult2] default.apply(x)
            }
        override final def isDefinedAt(x: Object): Boolean = 
          this.isDefinedAt(x.asInstanceOf[String])
        override final def applyOrElse(x: Object, default: Function1): Object = 
          this.applyOrElse(x.asInstanceOf[String], default)
      }
      new scala.runtime.AbstractPartialFunction with java.io.Serializable {...}(
        )
      :scala.runtime.AbstractPartialFunction
    }
  }
)
java.util.NoSuchElementException: key not found: method $anonfun while traversing def foo(): scala.collection.immutable.List = 
  List().apply(scala.runtime.ScalaRunTime.wrapRefArray(["1","two","3" : String])
    )
  .asInstanceOf[scala.collection.immutable.List].collect(
    {
      {
        final class $anon extends scala.runtime.AbstractPartialFunction, 
          java.io.Serializable
         {
          def <init>(): Unit = 
            {
              super()
              ()
            }
          override final def isDefinedAt(x: String): Boolean = 
            matchResult1[Boolean]: 
              {
                case val x1: scala.util.Try = 
                  util.Try.apply(
                    {
                      def $anonfun(): Int = 
                        scala.collection.StringOps.toInt$extension(
                          augmentString(x)
                        ):Int
                      closure($anonfun:JFunction0$mcI$sp)
                    }
                  ):scala.util.Try
                if x1.isInstanceOf[scala.util.Success] then 
                  {
                    case val int: Int = 
                      scala.Int.unbox(
                        x1.asInstanceOf[scala.util.Success].value()
                      )
                    return[matchResult1] true
                  }
                 else ()
                return[matchResult1] false
              }
          override final def applyOrElse(x: String, default: Function1): Object
             = 
          matchResult2[Object]: 
            {
              case val x4: scala.util.Try = 
                util.Try.apply(
                  {
                    def $anonfun(): Int = 
                      scala.collection.StringOps.toInt$extension(
                        augmentString(x)
                      ):Int
                    closure($anonfun:JFunction0$mcI$sp)
                  }
                ):scala.util.Try
              if x4.isInstanceOf[scala.util.Success] then 
                {
                  case val int: Int = 
                    scala.Int.unbox(x4.asInstanceOf[scala.util.Success].value())
                  return[matchResult2] 
                    {
                      scala.Int.box(int:Int)
                    }
                }
               else ()
              return[matchResult2] default.apply(x)
            }
          override final def isDefinedAt(x: Object): Boolean = 
            this.isDefinedAt(x.asInstanceOf[String])
          override final def applyOrElse(x: Object, default: Function1): Object
             = 
          this.applyOrElse(x.asInstanceOf[String], default)
        }
        new 
          scala.runtime.AbstractPartialFunction with java.io.Serializable {...}
        ():scala.runtime.AbstractPartialFunction
      }
    }
  )
java.util.NoSuchElementException: key not found: method $anonfun while traversing  extends Object {
  def <init>(): Unit = 
    {
      super()
      ()
    }
  private def writeReplace(): Object = 
    new scala.runtime.ModuleSerializationProxy(classOf[FooBar$])
  def foo(): scala.collection.immutable.List = 
    List().apply(
      scala.runtime.ScalaRunTime.wrapRefArray(["1","two","3" : String])
    ).asInstanceOf[scala.collection.immutable.List].collect(
      {
        {
          final class $anon extends scala.runtime.AbstractPartialFunction, 
            java.io.Serializable
           {
            def <init>(): Unit = 
              {
                super()
                ()
              }
            override final def isDefinedAt(x: String): Boolean = 
              matchResult1[Boolean]: 
                {
                  case val x1: scala.util.Try = 
                    util.Try.apply(
                      {
                        def $anonfun(): Int = 
                          scala.collection.StringOps.toInt$extension(
                            augmentString(x)
                          ):Int
                        closure($anonfun:JFunction0$mcI$sp)
                      }
                    ):scala.util.Try
                  if x1.isInstanceOf[scala.util.Success] then 
                    {
                      case val int: Int = 
                        scala.Int.unbox(
                          x1.asInstanceOf[scala.util.Success].value()
                        )
                      return[matchResult1] true
                    }
                   else ()
                  return[matchResult1] false
                }
            override final def applyOrElse(x: String, default: Function1): 
              Object
             = 
              matchResult2[Object]: 
                {
                  case val x4: scala.util.Try = 
                    util.Try.apply(
                      {
                        def $anonfun(): Int = 
                          scala.collection.StringOps.toInt$extension(
                            augmentString(x)
                          ):Int
                        closure($anonfun:JFunction0$mcI$sp)
                      }
                    ):scala.util.Try
                  if x4.isInstanceOf[scala.util.Success] then 
                    {
                      case val int: Int = 
                        scala.Int.unbox(
                          x4.asInstanceOf[scala.util.Success].value()
                        )
                      return[matchResult2] 
                        {
                          scala.Int.box(int:Int)
                        }
                    }
                   else ()
                  return[matchResult2] default.apply(x)
                }
            override final def isDefinedAt(x: Object): Boolean = 
              this.isDefinedAt(x.asInstanceOf[String])
            override final def applyOrElse(x: Object, default: Function1): 
              Object
             = this.applyOrElse(x.asInstanceOf[String], default)
          }
          new 
            scala.runtime.AbstractPartialFunction with java.io.Serializable 
              {...}
            
          ():scala.runtime.AbstractPartialFunction
        }
      }
    )
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing @scala.annotation.internal.SourceFile("test.scala") final module class FooBar$
   extends
 Object {
  def <init>(): Unit = 
    {
      super()
      ()
    }
  private def writeReplace(): Object = 
    new scala.runtime.ModuleSerializationProxy(classOf[FooBar$])
  def foo(): scala.collection.immutable.List = 
    List().apply(
      scala.runtime.ScalaRunTime.wrapRefArray(["1","two","3" : String])
    ).asInstanceOf[scala.collection.immutable.List].collect(
      {
        {
          final class $anon extends scala.runtime.AbstractPartialFunction, 
            java.io.Serializable
           {
            def <init>(): Unit = 
              {
                super()
                ()
              }
            override final def isDefinedAt(x: String): Boolean = 
              matchResult1[Boolean]: 
                {
                  case val x1: scala.util.Try = 
                    util.Try.apply(
                      {
                        def $anonfun(): Int = 
                          scala.collection.StringOps.toInt$extension(
                            augmentString(x)
                          ):Int
                        closure($anonfun:JFunction0$mcI$sp)
                      }
                    ):scala.util.Try
                  if x1.isInstanceOf[scala.util.Success] then 
                    {
                      case val int: Int = 
                        scala.Int.unbox(
                          x1.asInstanceOf[scala.util.Success].value()
                        )
                      return[matchResult1] true
                    }
                   else ()
                  return[matchResult1] false
                }
            override final def applyOrElse(x: String, default: Function1): 
              Object
             = 
              matchResult2[Object]: 
                {
                  case val x4: scala.util.Try = 
                    util.Try.apply(
                      {
                        def $anonfun(): Int = 
                          scala.collection.StringOps.toInt$extension(
                            augmentString(x)
                          ):Int
                        closure($anonfun:JFunction0$mcI$sp)
                      }
                    ):scala.util.Try
                  if x4.isInstanceOf[scala.util.Success] then 
                    {
                      case val int: Int = 
                        scala.Int.unbox(
                          x4.asInstanceOf[scala.util.Success].value()
                        )
                      return[matchResult2] 
                        {
                          scala.Int.box(int:Int)
                        }
                    }
                   else ()
                  return[matchResult2] default.apply(x)
                }
            override final def isDefinedAt(x: Object): Boolean = 
              this.isDefinedAt(x.asInstanceOf[String])
            override final def applyOrElse(x: Object, default: Function1): 
              Object
             = this.applyOrElse(x.asInstanceOf[String], default)
          }
          new 
            scala.runtime.AbstractPartialFunction with java.io.Serializable 
              {...}
            
          ():scala.runtime.AbstractPartialFunction
        }
      }
    )
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing package <empty> {
  final lazy module val FooBar: FooBar$ = new FooBar$()
  @scala.annotation.internal.SourceFile("test.scala") final module class FooBar$
     extends
   Object {
    def <init>(): Unit = 
      {
        super()
        ()
      }
    private def writeReplace(): Object = 
      new scala.runtime.ModuleSerializationProxy(classOf[FooBar$])
    def foo(): scala.collection.immutable.List = 
      List().apply(
        scala.runtime.ScalaRunTime.wrapRefArray(["1","two","3" : String])
      ).asInstanceOf[scala.collection.immutable.List].collect(
        {
          {
            final class $anon extends scala.runtime.AbstractPartialFunction, 
              java.io.Serializable
             {
              def <init>(): Unit = 
                {
                  super()
                  ()
                }
              override final def isDefinedAt(x: String): Boolean = 
                matchResult1[Boolean]: 
                  {
                    case val x1: scala.util.Try = 
                      util.Try.apply(
                        {
                          def $anonfun(): Int = 
                            scala.collection.StringOps.toInt$extension(
                              augmentString(x)
                            ):Int
                          closure($anonfun:JFunction0$mcI$sp)
                        }
                      ):scala.util.Try
                    if x1.isInstanceOf[scala.util.Success] then 
                      {
                        case val int: Int = 
                          scala.Int.unbox(
                            x1.asInstanceOf[scala.util.Success].value()
                          )
                        return[matchResult1] true
                      }
                     else ()
                    return[matchResult1] false
                  }
              override final def applyOrElse(x: String, default: Function1): 
                Object
               = 
                matchResult2[Object]: 
                  {
                    case val x4: scala.util.Try = 
                      util.Try.apply(
                        {
                          def $anonfun(): Int = 
                            scala.collection.StringOps.toInt$extension(
                              augmentString(x)
                            ):Int
                          closure($anonfun:JFunction0$mcI$sp)
                        }
                      ):scala.util.Try
                    if x4.isInstanceOf[scala.util.Success] then 
                      {
                        case val int: Int = 
                          scala.Int.unbox(
                            x4.asInstanceOf[scala.util.Success].value()
                          )
                        return[matchResult2] 
                          {
                            scala.Int.box(int:Int)
                          }
                      }
                     else ()
                    return[matchResult2] default.apply(x)
                  }
              override final def isDefinedAt(x: Object): Boolean = 
                this.isDefinedAt(x.asInstanceOf[String])
              override final def applyOrElse(x: Object, default: Function1): 
                Object
               = this.applyOrElse(x.asInstanceOf[String], default)
            }
            new 
              scala.runtime.AbstractPartialFunction with java.io.Serializable 
                {...}
              
            ():scala.runtime.AbstractPartialFunction
          }
        }
      )
  }
}
exception occurred while compiling test.scala
java.util.NoSuchElementException: key not found: method $anonfun while compiling test.scala
Exception in thread "main" java.util.NoSuchElementException: key not found: method $anonfun
	at scala.collection.MapOps.default(Map.scala:251)
	at scala.collection.MapOps.default$(Map.scala:250)
	at scala.collection.AbstractMap.default(Map.scala:381)
	at scala.collection.MapOps.apply(Map.scala:153)
	at scala.collection.MapOps.apply$(Map.scala:152)
	at scala.collection.AbstractMap.apply(Map.scala:381)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.narrowLiftedOwner(LambdaLift.scala:99)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.dotty$tools$dotc$transform$LambdaLift$Lifter$$markFree(LambdaLift.scala:162)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.dotty$tools$dotc$transform$LambdaLift$Lifter$$markFree(LambdaLift.scala:161)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:212)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1408)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1408)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1416)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1477)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1422)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1408)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1416)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1473)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1422)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1432)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1477)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1484)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1481)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1422)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1422)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1408)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1477)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1484)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1481)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1512)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1389)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1488)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1513)
	at dotty.tools.dotc.transform.LambdaLift$Lifter$CollectDependencies.traverse(LambdaLift.scala:250)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.<init>(LambdaLift.scala:374)
	at dotty.tools.dotc.transform.LambdaLift.prepareForUnit(LambdaLift.scala:531)
	at dotty.tools.dotc.transform.MegaPhase.prepUnit(MegaPhase.scala:1040)
	at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:447)
	at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:460)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:296)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:297)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:185)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:195)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:203)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:210)
	at dotty.tools.dotc.Run.compileSources(Run.scala:147)
	at dotty.tools.dotc.Run.compile(Run.scala:129)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
	at dotty.tools.dotc.Driver.process(Driver.scala:195)
	at dotty.tools.dotc.Driver.process(Driver.scala:164)
	at dotty.tools.dotc.Driver.process(Driver.scala:176)
	at dotty.tools.dotc.Driver.main(Driver.scala:203)
	at dotty.tools.dotc.Main.main(Main.scala)

Expectation

This compiles in Scala 2.13, and evaluates to List(1, 3).

@Jasper-M
Copy link
Contributor Author

Jasper-M commented Nov 19, 2020

It's caused by the by-name argument to Try in combination with the PartialFunction.

def foo[A](a: =>A): Option[A] = Some(a)

// crash
val f: PartialFunction[String, Int] = x => foo(x.toInt) match { case Some(0) => 0 }

// no crash
val f: String => Int = x => foo(x.toInt) match { case Some(0) => 0 }

// no crash
val f: PartialFunction[String, Int] = x => Option(x.toInt) match { case Some(0) => 0 }

@Jasper-M Jasper-M changed the title Unusual PartialFunction says "key not found: method $anonfun" By-name argument in PartialFunction says "key not found: method $anonfun" Nov 19, 2020
@griggt
Copy link
Contributor

griggt commented Feb 9, 2021

I believe this is a duplicate of #9391, which has been fixed by #10979.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants