lang: funcs: Use more constants to build types

This commit is contained in:
James Shubin
2023-06-29 15:31:12 -04:00
parent df9b338279
commit d37862b123
5 changed files with 6 additions and 6 deletions

View File

@@ -348,7 +348,7 @@ func (obj *ContainsPolyFunc) Info() *interfaces.Info {
var sig *types.Type
if obj.Type != nil { // don't panic if called speculatively
s := obj.Type.String()
sig = types.NewType(fmt.Sprintf("func(needle %s, haystack []%s) bool", s, s))
sig = types.NewType(fmt.Sprintf("func(%s %s, %s []%s) bool", containsArgNameNeedle, s, containsArgNameHaystack, s))
}
return &interfaces.Info{
Pure: true,

View File

@@ -500,9 +500,9 @@ func (obj *SchedulePolyFunc) Info() *interfaces.Info {
// before you're built. Type unification may call it opportunistically.
var typ *types.Type
if obj.built {
typ = types.NewType("func(namespace str) []str") // simplest form
typ = types.NewType(fmt.Sprintf("func(%s str) []str", scheduleArgNameNamespace)) // simplest form
if obj.Type != nil {
typ = types.NewType(fmt.Sprintf("func(namespace str, opts %s) []str", obj.Type.String()))
typ = types.NewType(fmt.Sprintf("func(%s str, %s %s) []str", scheduleArgNameNamespace, scheduleArgNameOpts, obj.Type.String()))
}
}
return &interfaces.Info{

View File

@@ -345,7 +345,7 @@ func (obj *HistoryFunc) Info() *interfaces.Info {
var sig *types.Type
if obj.Type != nil { // don't panic if called speculatively
s := obj.Type.String()
sig = types.NewType(fmt.Sprintf("func(value %s, index int) %s", s, s))
sig = types.NewType(fmt.Sprintf("func(%s %s, %s int) %s", historyArgNameValue, s, historyArgNameIndex, s))
}
return &interfaces.Info{
Pure: false, // definitely false

View File

@@ -534,7 +534,7 @@ func (obj *MapLookupPolyFunc) Info() *interfaces.Info {
// TODO: can obj.Type.Key or obj.Type.Val be nil (a partial) ?
k := obj.Type.Key.String()
v := obj.Type.Val.String()
typ = types.NewType(fmt.Sprintf("func(map %s, key %s, default %s) %s", obj.Type.String(), k, v, v))
typ = types.NewType(fmt.Sprintf("func(%s %s, %s %s, %s %s) %s", mapLookupArgNameMap, obj.Type.String(), mapLookupArgNameKey, k, mapLookupArgNameDef, v, v))
}
return &interfaces.Info{
Pure: true,

View File

@@ -459,7 +459,7 @@ func (obj *StructLookupPolyFunc) Info() *interfaces.Info {
var sig *types.Type
if obj.Type != nil { // don't panic if called speculatively
// TODO: can obj.Out be nil (a partial) ?
sig = types.NewType(fmt.Sprintf("func(struct %s, field str) %s", obj.Type.String(), obj.Out.String()))
sig = types.NewType(fmt.Sprintf("func(%s %s, %s str) %s", structLookupArgNameStruct, obj.Type.String(), structLookupArgNameField, obj.Out.String()))
}
return &interfaces.Info{
Pure: true,