Skip to content

Instantly share code, notes, and snippets.

@btab
Created December 11, 2016 17:56
Show Gist options
  • Save btab/1d814e886e9216c26cf0be485c1a0f5d to your computer and use it in GitHub Desktop.
Save btab/1d814e886e9216c26cf0be485c1a0f5d to your computer and use it in GitHub Desktop.
use "collections"
actor Main
let m1: Map[String, String] = Map[String, String]
let m2: Map[String, Array[String]] = Map[String, Array[String]]
// works fine
fun getThingsStringLiteral(): String =>
m1.get_or_else("foo", "")
// works fine
fun getThingsStringRefRecovered(): String =>
m1.get_or_else("foo", recover val String end)
// Array[String val] ref is not a subtype of Array[String val] #read: ref is not a subtype of #read
fun getThingsStringArrayLiteral(): Array[String] =>
m2.get_or_else("foo", [""])
// Array[String val] val is not a subtype of Array[String val] #read: val is not a subtype of #read
fun getThingsStringArrayRefRecovered(): Array[String] =>
m2.get_or_else("foo", recover val Array[String] end)
@SeanTAllen
Copy link

There's some problems lurking in here...

  fun getThingsStringArrayRefRecovered(): Array[String] =>
    m2.get_or_else("foo", recover val Array[String] end)

So m2 will return a Array[String] ref however your else is Array[String] val.
That would be a problem.

I think you wanted something more like...

fun getThingsStringArrayRefRecovered(): this->Array[String] =>
m2.get_or_else("1", recover Array[String] end)

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