Skip to content

Instantly share code, notes, and snippets.

@jimkang
Created July 6, 2018 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimkang/ac798bcc18f469ae027e1d19d55bd5af to your computer and use it in GitHub Desktop.
Save jimkang/ac798bcc18f469ae027e1d19d55bd5af to your computer and use it in GitHub Desktop.
Fairly similar lines of code seem to compile differently here.
def render(s: String, mode: NameMode): String =
if (s.matches("\\d+")) {
return render(SafeLong(s.toInt), mode);
// The line below seems to compile.
} else if (s.charAt(0) == '-') {
"negative " + render(s.substring(1).toInt, mode)
} else if (s.length < 2) {
val c = s.charAt(0)
if (charIsAlpha(c)) {
onesForChar(c)
} else {
mode.ones(c.toInt)
}
} else if (s.length < 3) {
val firstChar:Char = s.charAt(0)
val secondChar = s.charAt(1)
// This line does not compile. `[error] /Users/jimkang/gcw/zillion/src/main/scala/zillion/Util.scala:82:7: type mismatch;
// [error] found : Unit
// [error] required: String
// [error] if (firstChar == '1') {
// [error] ^
if (firstChar == '1') {
if (charIsAlpha(s.charAt(1))) {
teensForChar(s.charAt(1))
} else {
mode.teens(s.toInt - 10)
}
}
...
} else {
throw new IllegalArgumentException(s"number is >= 10^3003")
}
@jimkang
Copy link
Author

jimkang commented Jul 6, 2018

I think this was actually a scope issue. This worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment