Invalid stubs for Scala (Uppercase Variables)

I encountered the bug in Mime Types puzzle

mime type line contains two “words” separated by a space
stubs for reading it looks like this:

val Array(EXT, MT) = readLine split " "

and it produces following errors:

/tmp/Solution.scala:14: error: not found: value EXT
        val Array(EXT, MT) = readLine split " "
/tmp/Solution.scala:14: error: not found: value MT
        val Array(EXT, MT) = readLine split " "

the thing is that this code uses patter matching and identifiers that starts with upper case letters are treated like constants to match against (so called “stable identifiers”).

this code can be fixed in two ways.
First (good and canonical) way is to convert variables into lower case:

val Array(ext, mt) = readLine split " "

Second way, ugly and bad, is to read result into separate array variable and extract values later:

val inputs = readLine split " "
val EXT = inputs(0)
val MT = inputs(1)
1 Like

indeed, same problem has been reported on Mars Lander puzzle a few months ago. It’s still in our bugs backlog. Thanks for reporting it.