lang: core: Let lookup function specialize earlier
If we happen to know some information, we can specialize early and help type unification solve things.
This commit is contained in:
22
lang/interpret_test/TestAstFunc2/lookup4.txtar
Normal file
22
lang/interpret_test/TestAstFunc2/lookup4.txtar
Normal file
@@ -0,0 +1,22 @@
|
||||
-- main.mcl --
|
||||
# FIXME: We'd instead love to do this during type unification with a callback or
|
||||
# similar, but at least for now we can handle some common cases.
|
||||
$bigmap = {
|
||||
"key1" => {
|
||||
"foo" => "thing1a",
|
||||
"bar" => "thing1b",
|
||||
},
|
||||
"key2" => {
|
||||
"foo" => "hello", # pull out this!
|
||||
"bar" => "thing2b",
|
||||
},
|
||||
}
|
||||
|
||||
$key = "key2"
|
||||
|
||||
#$inner map{str: str} = $bigmap[$key] # does unify with the type hint!
|
||||
$inner = $bigmap[$key] # doesn't unify without special function code!
|
||||
|
||||
test [$inner["foo"],] {}
|
||||
-- OUTPUT --
|
||||
Vertex: test[hello]
|
||||
22
lang/interpret_test/TestAstFunc2/lookup5.txtar
Normal file
22
lang/interpret_test/TestAstFunc2/lookup5.txtar
Normal file
@@ -0,0 +1,22 @@
|
||||
-- main.mcl --
|
||||
# FIXME: We'd instead love to do this during type unification with a callback or
|
||||
# similar, but at least for now we can handle some common cases.
|
||||
$bigmap = {
|
||||
1 => {
|
||||
42 => "thing1a",
|
||||
13 => "thing1b",
|
||||
},
|
||||
2 => {
|
||||
42 => "hello", # pull out this!
|
||||
13 => "thing2b",
|
||||
},
|
||||
}
|
||||
|
||||
$key = 2
|
||||
|
||||
#$inner map{str: str} = $bigmap[$key] # does unify with the type hint!
|
||||
$inner = $bigmap[$key] # doesn't unify!
|
||||
|
||||
test [$inner[42],] {}
|
||||
-- OUTPUT --
|
||||
Vertex: test[hello]
|
||||
Reference in New Issue
Block a user