//KT-10934 compiler throws UninferredParameterTypeConstructor in when block that covers all types class Parser(val f: (TInput) -> Result) { operator fun invoke(input: TInput): Result = f(input) fun mapJoin( selector: (TValue) -> Parser, projector: (TValue, TIntermediate) -> TValue2 ): Parser { return Parser({ input -> val res = this(input) when (res) { is Result.ParseError -> Result.ParseError(res.productionLabel, res.child, res.rest) is Result.Value -> { val v = res.value val res2 = selector(v)(res.rest) when (res2) { is Result.ParseError -> Result.ParseError(res2.productionLabel, res2.child, res2.rest) is Result.Value -> Result.Value(projector(v, res2.value), res2.rest) } } } }) } } /** A parser can return one of two Results */ sealed class Result { class Value(val value: TValue, val rest: TInput) : Result() {} class ParseError(val productionLabel: String, val child: ParseError?, val rest: TInput) : Result() {} } fun box() = "OK"