Home Articles

在未明确指定通用参数的情况下,在构建期间发生UninferredParameterTypeConstructor异常

Asked
Viewed 656 times
0

我有以下代码(使用 RxKotlin 0.40.1 ):

class Result<T, E>(val data: T? = null, val error: E? = null)

fun <T, E> wrapResult(errorInfoFactory: (Throwable) -> E): (Observable<T>) -> Observable<Result<T, E>> = { it.map { Result<T, E>(it) }.onErrorReturn { Result<T, E>(error = errorInfoFactory(it)) } }

仅供参考,需要轻松转换 Observable ,这可能会将错误抛给 Observable ,它始终返回 Result 对象,因此 onError 永远不会被触发 .

我想像这样使用它:

fun dangerousOperation() = 0

fun getErrorMessage(t: Throwable) = "error occurred"

fun test() {
    val resultObservable = Observable.fromCallable(::dangerousOperation).compose(wrapResult(::getErrorMessage))
}

Android Studio 1.5.1Kotlin plugin 1.0.0-release-IJ141-56 并未突出显示此代码中的任何错误 . 但是当我尝试构建它时,我得到错误:

//错误:(24,9)org.jetbrains.kotlin.codegen.CompilationException:后端(JVM)内部错误:遇到错误类型:org.jetbrains.kotlin.types.ErrorUtils$UninferredParameterTypeConstructor@68754e6(ErrorTypeImpl) . //原因:遇到错误类型:org.jetbrains.kotlin.types.ErrorUtils$UninferredParameterTypeConstructor@68754e6(ErrorTypeImpl) . //正在编译的文件和位置:(24,9)在/home/d/work/workspace/Hitch-hiking-Stats/app/src/main/java/ru/netimen/hitch_hikingstats/MemoryRepo.kt // PsiElement: val resultObservable = Observable.just(dangerousOperation()) . compose(wrapResult(:: getErrorMessage))//引发根本原因:JetTypeMapper.java:435 // at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified( ExpressionCodegen.java:299)// at org.jetbrains.kotlin.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:339)// at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1532)// at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1485)// at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitBlockExpression(CodegenStatementVisitor.java:56)// at org.jetbrains.kotlin.codegen .CodegenStatementVisitor.visitBlockExpression(CodegenStatementVisitor.java:22)// at org.jetbrains.kotlin.psi.KtBlockExpression.accept(KtBlockExpression.ja va:44)// at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:280)// at org.jetbrains.kotlin.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:339)// at org .jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:309)// at org.jetbrains.kotlin.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:1873)// at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy $ FunctionDefault.doGenerateBody(FunctionGenerationStrategy.java:50)// at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy $ CodegenBased.generateBody(FunctionGenerationStrategy.java:72)// at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen) .java:364)// at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:203)// at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:138)

但是当我将 test 函数更改为

fun test() {
    val resultObservable = Observable.fromCallable(::dangerousOperation).compose(wrapResult<Int, String>(::getErrorMessage))
}

一切都编好了 . 但是,如果IDE没有突出显示任何错误,当我没有明确指定 wrapResult 的泛型参数时,为什么会出现该异常?

1 Answer

Related