// Generated from "lambdas/Lambdas.java"
@file:Suppress(
 "ALWAYS_NULL",
 "PARAMETER_NAME_CHANGED_ON_OVERRIDE",
 "SENSELESS_COMPARISON",
 "UNCHECKED_CAST",
 "UNNECESSARY_LATEINIT",
 "UNNECESSARY_NOT_NULL_ASSERTION",
 "UNREACHABLE_CODE",
 "UNUSED_ANONYMOUS_PARAMETER",
 "UNUSED_PARAMETER",
 "UNUSED_VARIABLE",
 "USELESS_CAST",
 "VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL",
 "VARIABLE_WITH_REDUNDANT_INITIALIZER",
 "REDUNDANT_ELSE_IN_WHEN")

package lambdas

import javaemul.lang.*
import java.lang.RuntimeException
import java.lang.Void
import javaemul.lang.MutableIterableJvm
import jsinterop.annotations.JsFunction
import jsinterop.annotations.JsMethod
import jsinterop.annotations.JsPackage
import jsinterop.annotations.JsType
import kotlin.Any
import kotlin.Double
import kotlin.Enum
import kotlin.Error
import kotlin.Int
import kotlin.Number
import kotlin.String
import kotlin.Suppress
import kotlin.Throwable
import kotlin.collections.MutableIterable
import kotlin.jvm.JvmField
import kotlin.jvm.JvmStatic
import kotlin.let

open class Lambdas {
 @JvmField
 var field: Int = 100

 open fun call(intf: FunctionalInterface?, n: Int): Int {
  return this.field + intf!!.m(n)
 }

 open fun testLambdaExpressionStyle() {
  this.call(
   FunctionalInterface { i: Int ->
    return@FunctionalInterface i + 1
   },
   10,
  )
 }

 open fun testLambdaBlockStyle() {
  this.call(
   FunctionalInterface { i: Int ->
    return@FunctionalInterface i + 2
   },
   10,
  )
 }

 open fun testLambdaCaptureField() {
  this.call(
   FunctionalInterface { i: Int ->
    return@FunctionalInterface this.field + i + 1
   },
   10,
  )
 }

 open fun testLambdaCaptureLocal() {
  val x: Int = 1
  this.call(
   FunctionalInterface { i: Int ->
    return@FunctionalInterface x + i + 1
   },
   10,
  )
 }

 open fun testLambdaCaptureFieldAndLocal() {
  val x: Int = 1
  this.call(
   FunctionalInterface { i: Int ->
    val y: Int = 1
    return@FunctionalInterface x + y + this.field + i + 1
   },
   10,
  )
 }

 open fun funOuter() {}

 open fun testLambdaCallOuterFunction() {
  this.call(
   FunctionalInterface { i: Int ->
    this.funOuter()
    this.funOuter()
    this@Lambdas.funOuter()
    return@FunctionalInterface i + 2
   },
   10,
  )
 }

 open fun testNestedLambdas() {
  this.call(
   FunctionalInterface { i: Int ->
    return@FunctionalInterface this.call(
     FunctionalInterface { j: Int ->
      return@FunctionalInterface j
     },
     20,
    )
   },
   10,
  )
 }

 open fun testReturnLabelNameConflictKotlin() {
  this.call(
   FunctionalInterface { i: Int ->
    return@FunctionalInterface i
   },
   10,
  )
 }

 open fun <T> testInstanceMethodTypeVariableThroughLambda() {
  val wrapped: Functional<T> = Functional { f: Functional<T>? ->
   return@Functional object : Functional<T> {
    override fun wrap(f: Functional<T>?): Functional<T>? {
     return null
    }
   }
  }
 }

 open fun <T> callWithTypeVariable(intf: GenericFunctionalInterface<T>?, e: T): T {
  return intf!!.m(e)
 }

 open fun callParameterized(intf: GenericFunctionalInterface<Error?>?, e: Error?): Error? {
  return intf!!.m(e)
 }

 internal open fun <T> callWithBiFunction_pp_lambdas(fn: BiFunction<T, String?, Double?>?): GenericFunctionalInterface<T>? {
  return null
 }

 open fun <T: Enum<T>> testLambdaWithGenerics() {
  this.callWithTypeVariable<Error?>(
   GenericFunctionalInterface { i: Error? ->
    return@GenericFunctionalInterface i
   },
   java.lang.Error(),
  )
  this.callParameterized(
   GenericFunctionalInterface { i_1: Error? ->
    return@GenericFunctionalInterface i_1
   },
   java.lang.Error(),
  )
  Lambdas.callTypeVariableWithBounds<T>(
   GenericFunctionalInterface { i_2: Enum<T>? ->
    return@GenericFunctionalInterface i_2
   } as GenericFunctionalInterface<Enum<T>?>?,
   null as Enum<T>?,
  )
  this.callWithBiFunction_pp_lambdas<Any?>(
   BiFunction { x: Any?, y: String? ->
    throw RuntimeException()
   },
  )
  this.callWithBiFunction_pp_lambdas<Any?>(
   BiFunction { x_1: Any?, y_1: String? ->
    return@BiFunction 3.0
   },
  )
  val f: Function<in T, *> = Function { item: T ->
   return@Function 1L
  }
  val f2: Function<Wrapper<String?>?, String?> = Function { item_1: Wrapper<String?>? ->
   return@Function item_1!!.wrapped_pp_lambdas
  }
 }

 open fun testLambdaReturningVoidAsExpression() {
  val runner: FunctionalInterfaceWithMethodReturningVoid = FunctionalInterfaceWithMethodReturningVoid {
   Any()
  }
 }

 open fun testAnonymousInsideLambda() {
  val runner: FunctionalInterfaceWithMethodReturningVoid = FunctionalInterfaceWithMethodReturningVoid {
   object : Any() {}
  }
 }

 open fun testDefaultMethodsInIntersectionAdaptor() {
  val o: Any = (BiFunction { t: String?, u: String? ->
   return@BiFunction null
  }).let { it as BiFunction<String?, String?, String?>; it as MarkerWithDefaultMethod; it }
 }

 companion object {
  @JvmStatic
  fun testLambdaInStaticContext() {
   val f: FunctionalInterface = FunctionalInterface { i: Int ->
    return@FunctionalInterface i
   }
  }

  @JvmStatic
  fun <T> testStaticMethodTypeVariableThroughLambda() {
   val wrapped: Functional<T> = Functional { f: Functional<T>? ->
    return@Functional object : Functional<T> {
     override fun wrap(f: Functional<T>?): Functional<T>? {
      return null
     }
    }
   }
  }

  @JvmStatic
  fun <T: Enum<T>> callTypeVariableWithBounds(intf: GenericFunctionalInterface<Enum<T>?>?, e: Enum<T>?): Enum<T>? {
   return intf!!.m(e)
  }

  @JvmStatic
  fun m(): Any? {
   return null
  }

  @JvmStatic
  fun testLambdaCallingStaticMethod() {
   val f: Function<Any?, *> = Function { l: Any? ->
    return@Function Lambdas.m()
   }
  }

  private var identityFunction: IdentityFunction? = null

  @JvmStatic
  fun <E> identity(): GenericJsFunction<E, E>? {
   if (Lambdas.identityFunction == null) {
    Lambdas.identityFunction = IdentityFunction()
   }
   return Lambdas.identityFunction as GenericJsFunction<E, E>?
  }

  @JvmStatic
  fun testJsInteropLambdas() {
   val thenable: Thenable<String?> = Thenable { f1: GenericJsFunction<Void?, String?>?, f2: GenericJsFunction<Void?, Throwable?>? ->
    f1!!.apply(null)
   }
   val otherThenable: AnotherThenable<String?> = AnotherThenable { f1_1: GenericJsFunction<Void?, String?>?, f2_1: GenericJsFunction<Void?, Throwable?>? ->
    f1_1!!.apply(null)
   }
   val stringJsSupplier: JsSupplier<Int?> = JsSupplier {
    return@JsSupplier 1
   }
   stringJsSupplier.get()
   val equals: Equals<Any?> = stringJsSupplier as Equals<Any?>
   equals.equals(null)
   equals.get()
  }

  @JvmStatic
  fun <U, V> testIntersectionTyping() {
   var o: Any = (GenericFunctionalInterface { x: String? ->
    return@GenericFunctionalInterface x
   }).let { it as GenericFunctionalInterface<String?>; it as JustADefaultT<Number?>; it }
   o = (GenericFunctionalInterface { x_1: String? ->
    return@GenericFunctionalInterface x_1
   }).let { it as GenericFunctionalInterface<String?>; it as JustADefaultS<Number?>; it }
   o = (GenericFunctionalInterface { x_2: U ->
    return@GenericFunctionalInterface x_2
   }).let { it as GenericFunctionalInterface<U>; it as JustADefaultS<V>; it }
  }

  @JvmStatic
  fun <T> testIterable(iterable: MutableIterable<T>?) {
   val lambda: MutableIterable<T> = MutableIterableJvm {
    return@MutableIterableJvm iterable!!.iterator()
   }
  }

  @JvmStatic
  private fun <T> acceptsSupplier(supplier: Supplier<T>?) {}
 }

 fun interface FunctionalInterface {
  fun m(i: Int): Int
 }

 fun interface Functional<T> {
  fun wrap(f: Functional<T>?): Functional<T>?
 }

 fun interface GenericFunctionalInterface<T> {
  fun m(i: T): T
 }

 fun interface BiFunction<T, U, R> {
  fun apply(t: T, u: U): R

  fun <V> andThen(after: Function<in R, out V>?): BiFunction<T, U, V>? {
   return BiFunction { t: T, u: U ->
    return@BiFunction after!!.apply(
     this.apply(t, u),
    )
   }
  }
 }

 fun interface Function<T, R> {
  fun apply(t: T): R

  companion object {
   @JvmStatic
   fun <T> identity(): Function<T, T>? {
    return Function { t: T ->
     return@Function t
    }
   }
  }
 }

 open class Wrapper<T> internal constructor() {
  @JvmField
  internal var wrapped_pp_lambdas: T = null as T
 }

 fun interface FunctionalInterfaceWithMethodReturningVoid {
  fun run()
 }

 open class Parent internal constructor() {
  @JvmField
  var fieldInParent: Int = 0

  open fun funInParent() {}
 }

 open class LambdaInSubClass internal constructor(): Parent() {
  open fun testLambdaInSubclass() {
   val l: FunctionalInterface = FunctionalInterface { i: Int ->
    this.funInParent()
    this.funInParent()
    this@LambdaInSubClass.funInParent()
    var a: Int = this.fieldInParent
    a = this.fieldInParent
    a = this@LambdaInSubClass.fieldInParent
    return@FunctionalInterface a
   }
  }
 }

 @JsFunction
 fun interface GenericJsFunction<R, T> {
  fun apply(t: T): R
 }

 @JsType(name = "?", namespace = JsPackage.GLOBAL, isNative = true)
 fun interface Thenable<T> {
  fun then(f1: GenericJsFunction<Void?, T>?, f2: GenericJsFunction<Void?, Throwable?>?)
 }

 @JsType(name = "?", namespace = JsPackage.GLOBAL, isNative = true)
 fun interface AnotherThenable<T> {
  fun then(f1: GenericJsFunction<Void?, T>?, f2: GenericJsFunction<Void?, Throwable?>?)
 }

 class IdentityFunction internal constructor(): GenericJsFunction<Any?, Any?> {
  override fun apply(o: Any?): Any? {
   return o
  }
 }

 interface Equals<T> {
  fun get(): T {
   return null as T
  }
 }

 fun interface JsSupplier<T: Number?>: Equals<T> {
  @JsMethod
  override fun get(): T
 }

 interface JustADefaultT<T> {
  fun method(t: T) {}
 }

 interface JustADefaultS<S> {
  fun method(t: S) {}
 }

 interface MarkerWithDefaultMethod {
  fun defaultMethod() {}
 }

 fun interface Runnable {
  fun run()
 }

 open inner class Outer internal constructor() {
  internal open fun m_pp_lambdas() {}

  internal open fun n_pp_lambdas() {
   val r: Runnable = Runnable {
    this.m_pp_lambdas()
   }
  }
 }

 open inner class Super internal constructor() {
  internal open fun m_pp_lambdas() {}
 }

 open inner class Sub internal constructor(): Lambdas.Super() {
  internal open fun n_pp_lambdas() {
   val r: Runnable = object : Runnable {
    override fun run() {
     super<Super>@Sub.m_pp_lambdas()
    }
   }
  }
 }

 open inner class SubWithLambda internal constructor(): Lambdas.Super() {
  internal open fun n_pp_lambdas() {
   val r: Runnable = Runnable {
    super<Super>.m_pp_lambdas()
   }
  }
 }

 interface EmptyInterface

 fun interface EmptyInterfaceProvider {
  fun provide(): EmptyInterface?
 }

 open class ProviderHolder internal constructor() {
  companion object {
   @JvmField
   val emptyInterface: EmptyInterface? = object : EmptyInterface {}

   @JvmField
   val provideFromField: EmptyInterfaceProvider? = EmptyInterfaceProvider {
    return@EmptyInterfaceProvider ProviderHolder.emptyInterface
   }

   @JvmField
   val provideFromAnonImpl: EmptyInterfaceProvider? = EmptyInterfaceProvider {
    return@EmptyInterfaceProvider object : EmptyInterface {}
   }
  }
 }

 fun interface Supplier<T> {
  fun get(): T
 }

 annotation class J2ktIncompatible
}
