lang: funcs: Catch non-specific type build error
If you had ambiguous code, and specified an invalid type, this could sneak through and become a runtime error, instead of a compile-time error. We fix this and add a test.
This commit is contained in:
13
lang/interpret_test/TestAstFunc2/unify-template.txtar
Normal file
13
lang/interpret_test/TestAstFunc2/unify-template.txtar
Normal file
@@ -0,0 +1,13 @@
|
||||
-- main.mcl --
|
||||
import "sys"
|
||||
|
||||
$tmplvalues = struct{num => 42, load => $theload,}
|
||||
|
||||
$theload bool = sys.load()->x1 # wrong type, make sure the compiler catches it!
|
||||
|
||||
file "/tmp/datetime" {
|
||||
state => $const.res.file.state.exists,
|
||||
content => template("num: {{ .num }} seconds\nload average: {{ .load }}\n", $tmplvalues),
|
||||
}
|
||||
-- OUTPUT --
|
||||
# err: errUnify: error setting type: func() { <built-in:_struct_lookup> }, error: field x1 type error: base kind does not match (bool != float)
|
||||
Reference in New Issue
Block a user