lang: funcs: Ensure that Info sig's are invalid if not built yet

In case something in the type unification tries to speculatively call
Info before it's ready to produce a valid sig, make sure we only return
a definitive answer (non-nil, and no variant types) once we've
conclusively finished defining the signature.
This commit is contained in:
James Shubin
2021-05-19 10:33:35 -04:00
parent b3d1ed9e65
commit 95cfbd0fff
7 changed files with 68 additions and 44 deletions

View File

@@ -68,23 +68,26 @@ func (obj *CallFunc) Validate() error {
// Info returns some static info about itself.
func (obj *CallFunc) Info() *interfaces.Info {
typ := &types.Type{
Kind: types.KindFunc, // function type
Map: make(map[string]*types.Type),
Ord: []string{},
Out: obj.Type, // this is the output type for the expression
}
var typ *types.Type
if obj.Type != nil { // don't panic if called speculatively
typ = &types.Type{
Kind: types.KindFunc, // function type
Map: make(map[string]*types.Type),
Ord: []string{},
Out: obj.Type, // this is the output type for the expression
}
sig := obj.FuncType
if obj.Edge != "" {
typ.Map[obj.Edge] = sig // we get a function in
typ.Ord = append(typ.Ord, obj.Edge)
}
sig := obj.FuncType
if obj.Edge != "" {
typ.Map[obj.Edge] = sig // we get a function in
typ.Ord = append(typ.Ord, obj.Edge)
}
// add any incoming args
for _, key := range sig.Ord { // sig.Out, not sig!
typ.Map[key] = sig.Map[key]
typ.Ord = append(typ.Ord, key)
// add any incoming args
for _, key := range sig.Ord { // sig.Out, not sig!
typ.Map[key] = sig.Map[key]
typ.Ord = append(typ.Ord, key)
}
}
return &interfaces.Info{