Infer final expression returns in lambdas

This commit is contained in:
pavel 2026-08-27 23:31:46 +02:00
commit 72606e7818
6 changed files with 300 additions and 7 deletions

View file

@ -51,6 +51,11 @@ type ImportedClassType struct {
func (ImportedClassType) typeNode() {}
func (t ImportedClassType) String() string { return t.Package + "." + t.Class.Name }
type GoInterfaceType struct{ Name string }
func (GoInterfaceType) typeNode() {}
func (t GoInterfaceType) String() string { return t.Name }
type NullableType struct{ Element Type }
func (NullableType) typeNode() {}
@ -330,6 +335,17 @@ func inferTypeBindings(parameter, argument Type, bindings map[string]Type) {
inferTypeBindings(expected.Args[index], actual.Args[index], bindings)
}
}
case FunctionType:
actual, ok := argument.(FunctionType)
if !ok {
return
}
for index := range expected.Params {
if index < len(actual.Params) {
inferTypeBindings(expected.Params[index], actual.Params[index], bindings)
}
}
inferTypeBindings(expected.Result, actual.Result, bindings)
}
}
@ -341,6 +357,8 @@ func renderGoType(typ Type) string {
return "*" + value.Class.Name
case ImportedClassType:
return "*" + value.Package + "." + value.Class.Name
case GoInterfaceType:
return value.Name
case NullableType:
element := renderGoType(value.Element)
switch value.Element.(type) {