Kotlin higherorder函数(可调用引用)编译器崩溃

所以我搞乱了Kotlin的一些Android开发,并遇到了一个编译器bug …如果有人有一些输入,会很好。

可调用引用(在这种情况下通过parameter passing函数)的Kotlin示例正在崩溃我的环境。 对我来说,这绝对是这个语言的一个重要特征,而不是让它工作瘫痪。

我的环境是:
Android Studio 0.3.6
Kotlin插件0.6.602

任何有识之士将不胜感激

fun isOdd(x: Int) = x % 2 != 0 val numbers = listOf(1, 2, 3) println(numbers.filter(::isOdd)) 

而编译器的错误是:

 :1:org.jetbrains.jet.codegen.CompilationException: Back-end (JVM) Internal error: Cannot resolve: callableReferenceFakeCall File being compiled and position: (1,9) in dummy.kt PsiElement: callableReferenceFakeCall(p0) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:1893) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:80) at org.jetbrains.jet.lang.psi.JetCallExpression.accept(JetCallExpression.java:42) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:257) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:234) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:273) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:277) at org.jetbrains.jet.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2122) at org.jetbrains.jet.codegen.ExpressionCodegen.invokeFunction(ExpressionCodegen.java:2014) at org.jetbrains.jet.codegen.ExpressionCodegen$4.doGenerateBody(ExpressionCodegen.java:2531) at org.jetbrains.jet.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:106) at org.jetbrains.jet.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:290) at org.jetbrains.jet.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:143) at org.jetbrains.jet.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:94) at org.jetbrains.jet.codegen.ClosureCodegen.gen(ClosureCodegen.java:122) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallableReferenceExpression(ExpressionCodegen.java:2597) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallableReferenceExpression(ExpressionCodegen.java:80) at org.jetbrains.jet.lang.psi.JetCallableReferenceExpression.accept(JetCallableReferenceExpression.java:57) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:257) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:234) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:273) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:277) at org.jetbrains.jet.codegen.ExpressionCodegen.pushMethodArguments(ExpressionCodegen.java:2336) at org.jetbrains.jet.codegen.ExpressionCodegen.pushArgumentsAndInvoke(ExpressionCodegen.java:2138) at org.jetbrains.jet.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2134) at org.jetbrains.jet.codegen.ExpressionCodegen.invokeFunction(ExpressionCodegen.java:2014) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:1922) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:80) at org.jetbrains.jet.lang.psi.JetCallExpression.accept(JetCallExpression.java:42) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:257) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:234) at org.jetbrains.jet.codegen.ExpressionCodegen.visitDotQualifiedExpression(ExpressionCodegen.java:2605) at org.jetbrains.jet.codegen.ExpressionCodegen.visitDotQualifiedExpression(ExpressionCodegen.java:80) at org.jetbrains.jet.lang.psi.JetDotQualifiedExpression.accept(JetDotQualifiedExpression.java:34) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:257) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:234) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:273) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:277) at org.jetbrains.jet.codegen.ExpressionCodegen.pushMethodArguments(ExpressionCodegen.java:2336) at org.jetbrains.jet.codegen.ExpressionCodegen.pushArgumentsAndInvoke(ExpressionCodegen.java:2138) at org.jetbrains.jet.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2134) at org.jetbrains.jet.codegen.ExpressionCodegen.invokeFunction(ExpressionCodegen.java:2014) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:1922) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:80) at org.jetbrains.jet.lang.psi.JetCallExpression.accept(JetCallExpression.java:42) at org.jetbrains.jet.codegen.CodegenStatementVisitor.visitJetElement(CodegenStatementVisitor.java:31) at org.jetbrains.jet.codegen.CodegenStatementVisitor.visitJetElement(CodegenStatementVisitor.java:22) at org.jetbrains.jet.lang.psi.JetVisitor.visitExpression(JetVisitor.java:154) at org.jetbrains.jet.lang.psi.JetVisitor.visitCallExpression(JetVisitor.java:246) at org.jetbrains.jet.lang.psi.JetCallExpression.accept(JetCallExpression.java:42) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:257) at org.jetbrains.jet.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:286) at org.jetbrains.jet.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1429) at org.jetbrains.jet.codegen.ExpressionCodegen.visitBlockExpression(ExpressionCodegen.java:1288) at org.jetbrains.jet.codegen.ExpressionCodegen.visitBlockExpression(ExpressionCodegen.java:80) at org.jetbrains.jet.lang.psi.JetBlockExpression.accept(JetBlockExpression.java:47) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:257) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:234) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:273) at org.jetbrains.jet.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:1590) at org.jetbrains.jet.codegen.FunctionGenerationStrategy$FunctionDefault.doGenerateBody(FunctionGenerationStrategy.java:83) at org.jetbrains.jet.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:106) at org.jetbrains.jet.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:290) at org.jetbrains.jet.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:143) at org.jetbrains.jet.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:94) at org.jetbrains.jet.codegen.FunctionCodegen.gen(FunctionCodegen.java:80) at org.jetbrains.jet.codegen.MemberCodegen.genFunctionOrProperty(MemberCodegen.java:47) at org.jetbrains.jet.codegen.ClassBodyCodegen.generateDeclaration(ClassBodyCodegen.java:116) at org.jetbrains.jet.codegen.ImplementationBodyCodegen.generateDeclaration(ImplementationBodyCodegen.java:1594) at org.jetbrains.jet.codegen.ClassBodyCodegen.generateClassBody(ClassBodyCodegen.java:102) at org.jetbrains.jet.codegen.ClassBodyCodegen.generate(ClassBodyCodegen.java:69) at org.jetbrains.jet.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:91) at org.jetbrains.jet.codegen.NamespaceCodegen.generateClassOrObject(NamespaceCodegen.java:206) at org.jetbrains.jet.codegen.NamespaceCodegen.generate(NamespaceCodegen.java:178) at org.jetbrains.jet.codegen.NamespaceCodegen.generate(NamespaceCodegen.java:113) at org.jetbrains.jet.codegen.KotlinCodegenFacade.generateNamespace(KotlinCodegenFacade.java:71) at org.jetbrains.jet.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:60) at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.java:298) at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyzeAndGenerate(KotlinToJVMBytecodeCompiler.java:260) at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileBunchOfSources(KotlinToJVMBytecodeCompiler.java:187) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:142) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:48) at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:147) at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.compile(Tasks.kt:116) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.gradle.util.JavaMethod.invoke(JavaMethod.java:62) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201) at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:527) at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:510) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:283) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33) at org.gradle.internal.Factories$1.create(Factories.java:22) at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214) at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276) at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142) at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31) at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86) at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29) at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67) at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54) at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166) at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113) at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81) at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64) at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:70) at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:30) at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:108) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35) at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45) at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:42) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71) at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69) at org.gradle.util.Swapper.swap(Swapper.java:38) at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60) at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:59) at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45) at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:186) at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49) at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32) at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125) at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:48) at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:155) at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128) at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116) at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724) ^ :gf_publisher:compileDebugKotlin FAILED 

这确实是一个与本地函数(在函数内声明的函数)有关的错误。 作为解决方法,请使用以下代码:

 fun isOdd(x: Int) = x % 2 != 0 fun main(args: Array) { val numbers = listOf(1, 2, 3) println(numbers.filter(::isOdd)) } 

重要的是isOdd()被定义在任何函数之外。