Compilation error on a simple console app


#1

``


package ronin

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.IOException

fun main(args : Array<String>){
  System.out.print("what is good for you? ")
  var bufferRead = BufferedReader(InputStreamReader(System.in));
  var s = bufferRead.readLine();
}

Above code generates below’s error. It highlights the “(System.in”) expression.

``

org.jetbrains.jet.codegen.CompilationException: Back-end (JVM) Internal error: null Cause: java.lang.NullPointerException File being compiled and position: (18,55) in F:RepositoryDocDroidSamplesRoninsrcMain.kt The root cause was thrown at: ExpressionCodegen.java:906 at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:171) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:176) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:180) at org.jetbrains.jet.codegen.ExpressionCodegen.pushMethodArguments(ExpressionCodegen.java:1526) at org.jetbrains.jet.codegen.ExpressionCodegen.pushMethodArguments(ExpressionCodegen.java:1619) at org.jetbrains.jet.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:1393) at org.jetbrains.jet.codegen.ExpressionCodegen.generateJavaConstructorCall(ExpressionCodegen.java:2366) at org.jetbrains.jet.codegen.ExpressionCodegen.generateConstructorCall(ExpressionCodegen.java:2320) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:1273) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:60) at org.jetbrains.jet.lang.psi.JetCallExpression.accept(JetCallExpression.java:45) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:161) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:176) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:180) at org.jetbrains.jet.codegen.ExpressionCodegen.pushMethodArguments(ExpressionCodegen.java:1526) at org.jetbrains.jet.codegen.ExpressionCodegen.pushMethodArguments(ExpressionCodegen.java:1619) at org.jetbrains.jet.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:1393) at org.jetbrains.jet.codegen.ExpressionCodegen.generateJavaConstructorCall(ExpressionCodegen.java:2366) at org.jetbrains.jet.codegen.ExpressionCodegen.generateConstructorCall(ExpressionCodegen.java:2320) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:1273) at org.jetbrains.jet.codegen.ExpressionCodegen.visitCallExpression(ExpressionCodegen.java:60) at org.jetbrains.jet.lang.psi.JetCallExpression.accept(JetCallExpression.java:45) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:161) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:176) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:180) at org.jetbrains.jet.codegen.ExpressionCodegen.visitProperty(ExpressionCodegen.java:2303) at org.jetbrains.jet.codegen.ExpressionCodegen.visitProperty(ExpressionCodegen.java:60) at org.jetbrains.jet.lang.psi.JetProperty.accept(JetProperty.java:51) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:161) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:176) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:180) at org.jetbrains.jet.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:871) at org.jetbrains.jet.codegen.ExpressionCodegen.visitBlockExpression(ExpressionCodegen.java:737) at org.jetbrains.jet.codegen.ExpressionCodegen.visitBlockExpression(ExpressionCodegen.java:60) at org.jetbrains.jet.lang.psi.JetBlockExpression.accept(JetBlockExpression.java:50) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:161) at org.jetbrains.jet.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:176) at org.jetbrains.jet.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:951) at org.jetbrains.jet.codegen.FunctionCodegen.generatedMethod(FunctionCodegen.java:241) at org.jetbrains.jet.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:75) at org.jetbrains.jet.codegen.FunctionCodegen.gen(FunctionCodegen.java:65) at org.jetbrains.jet.codegen.MemberCodegen.generateFunctionOrProperty(MemberCodegen.java:45) at org.jetbrains.jet.codegen.NamespaceCodegen.generate(NamespaceCodegen.java:63) at org.jetbrains.jet.codegen.GenerationState.generateNamespace(GenerationState.java:149) at org.jetbrains.jet.codegen.GenerationState.compileCorrectFiles(GenerationState.java:132) at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.java:279) at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyzeAndGenerate(KotlinToJVMBytecodeCompiler.java:232) at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyzeAndGenerate(KotlinToJVMBytecodeCompiler.java:216) at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModule(KotlinToJVMBytecodeCompiler.java:80) at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.java:101) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:104) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:48) at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:114) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.exec(K2JVMCompiler.java:175) at org.jetbrains.jet.cli.jvm.K2JVMCompiler.exec(K2JVMCompiler.java:48) at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jetbrains.jet.plugin.compiler.CompilerUtils.invokeExecMethod(CompilerUtils.java:175) at org.jetbrains.jet.plugin.compiler.JetCompiler.execInProcess(JetCompiler.java:249) at org.jetbrains.jet.plugin.compiler.JetCompiler.access$000(JetCompiler.java:55) at org.jetbrains.jet.plugin.compiler.JetCompiler$1.invoke(JetCompiler.java:236) at org.jetbrains.jet.plugin.compiler.JetCompiler$1.invoke(JetCompiler.java:233) at org.jetbrains.jet.plugin.compiler.CompilerUtils.outputCompilerMessagesAndHandleExitCode(CompilerUtils.java:314) at org.jetbrains.jet.plugin.compiler.JetCompiler.runInProcess(JetCompiler.java:233) at org.jetbrains.jet.plugin.compiler.JetCompiler.runCompiler(JetCompiler.java:140) at org.jetbrains.jet.plugin.compiler.JetCompiler.doCompile(JetCompiler.java:128) at org.jetbrains.jet.plugin.compiler.JetCompiler.compile(JetCompiler.java:103) at com.intellij.compiler.impl.CompileDriver.compileSources(CompileDriver.java:1931) at com.intellij.compiler.impl.CompileDriver.translate(CompileDriver.java:1254) at com.intellij.compiler.impl.CompileDriver.doCompile(CompileDriver.java:986) at com.intellij.compiler.impl.CompileDriver.doCompile(CompileDriver.java:747) at com.intellij.compiler.impl.CompileDriver.access$1000(CompileDriver.java:104) at com.intellij.compiler.impl.CompileDriver$8.run(CompileDriver.java:665) at com.intellij.compiler.progress.CompilerTask.run(CompilerTask.java:155) at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:469) at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:218) at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:169) at com.intellij.openapi.progress.impl.ProgressManagerImpl$8.run(ProgressManagerImpl.java:378) at com.intellij.openapi.application.impl.ApplicationImpl$6.run(ApplicationImpl.java:434) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) at com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:145) Caused by: java.lang.NullPointerException at org.jetbrains.jet.codegen.ExpressionCodegen.markLineNumber(ExpressionCodegen.java:906) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:159) at org.jetbrains.jet.codegen.ExpressionCodegen.visitDotQualifiedExpression(ExpressionCodegen.java:1646) at org.jetbrains.jet.codegen.ExpressionCodegen.visitDotQualifiedExpression(ExpressionCodegen.java:60) at org.jetbrains.jet.lang.psi.JetDotQualifiedExpression.accept(JetDotQualifiedExpression.java:37) at org.jetbrains.jet.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:161) ... 89 more


#2

Thanks for the report.

‘in’ is a keyword in Kotlin. The correc code is:

``

package ronin

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.IOException

fun main(args : Array<String>){
  System.out.print("what is good for you? ")
  var bufferRead = BufferedReader(InputStreamReader(System.in));
  var s = bufferRead.readLine();
}


#3

THis is a bug in the compiler reporting subsystem: http://youtrack.jetbrains.com/issue/KT-2207


#4

"Sytem.`in`" looks very ugly.

Can’t you teach the parser that strings which directly follow a dot are always supposed to be identifiers and not operators?


#5

Keywords exist for a reason: you can't name your field 'class', or 'if', nor you can name it 'in': it would confuse people and the parser.

Actually, this is not a problem, because you don’t need to use ‘System.in’ (or ‘System.out’) in Kotlin. See the API docs for standard IO functions:
http://jetbrains.github.com/kotlin/versions/snapshot/apidocs/index.html